Skip to content

Commit

Permalink
Generate man pages with hidden 'man' command
Browse files Browse the repository at this point in the history
  • Loading branch information
muesli committed Feb 3, 2022
1 parent 54a374b commit 4977212
Show file tree
Hide file tree
Showing 15 changed files with 146 additions and 37 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/manpage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: manpage

on:
push:
branches:
- master

jobs:
manpage:
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.17

- name: Checkout code
uses: actions/checkout@v2

- name: Download Go modules
run: go mod download

- name: Build
run: go build -v -tags mango

- name: Generate man-page
run: ./obs-cli man > obs-cli.1

- name: Commit
uses: stefanzweifel/git-auto-commit-action@v4
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
commit_message: "docs: update man page"
branch: master
commit_user_name: mango 🤖
commit_user_email: [email protected]
commit_author: mango 🤖 <[email protected]>
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,11 @@ Display virtual camera status:
```
obs-cli virtualcam status
```

## Development

You can regenerate the man pages with:

```
go run -tags man . man ./man
```
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ require (
github.com/andreykaipov/goobs v0.8.0
github.com/dustin/go-humanize v1.0.0
github.com/muesli/coral v1.0.0
github.com/muesli/mango-coral v1.0.1
github.com/muesli/roff v0.1.0
)
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NH
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/muesli/coral v1.0.0 h1:odyqkoEg4aJAINOzvnjN4tUsdp+Zleccs7tRIAkkYzU=
github.com/muesli/coral v1.0.0/go.mod h1:bf91M/dkp7iHQw73HOoR9PekdTJMTD6ihJgWoDitde8=
github.com/muesli/mango v0.1.0 h1:DZQK45d2gGbql1arsYA4vfg4d7I9Hfx5rX/GCmzsAvI=
github.com/muesli/mango v0.1.0/go.mod h1:5XFpbC8jY5UUv89YQciiXNlbi+iJgt29VDC5xbzrLL4=
github.com/muesli/mango-coral v1.0.1 h1:W3nGbUC/q5vLscQ6GPzteHZrJI1Msjw5Hns82o0xRkI=
github.com/muesli/mango-coral v1.0.1/go.mod h1:EPSlYH67AtcxQrxssNw6r/lMFxHTjuDoGfq9Uxxevhg=
github.com/muesli/mango-pflag v0.1.0 h1:UADqbYgpUyRoBja3g6LUL+3LErjpsOwaC9ywvBWe7Sg=
github.com/muesli/mango-pflag v0.1.0/go.mod h1:YEQomTxaCUp8PrbhFh10UfbhbQrM/xJ4i2PB8VTLLW0=
github.com/muesli/roff v0.1.0 h1:YD0lalCotmYuF5HhZliKWlIx7IEhiXeSfq7hNjFqGF8=
github.com/muesli/roff v0.1.0/go.mod h1:pjAHQM9hdUUwm/krAfrLGgJkXJ+YuhtsfZ42kieB2Ig=
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d h1:VhgPp6v9qf9Agr/56bj7Y/xa04UccTW04VP0Qed4vnQ=
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down
9 changes: 5 additions & 4 deletions label.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import (

var (
labelCmd = &coral.Command{
Use: "label",
Short: "manage text labels",
Long: `The label command manages text labels`,
RunE: nil,
Use: "label",
Short: "manage text labels",
Long: `The label command manages text labels`,
RunE: nil,
PersistentPreRun: connectOBSCommand,
}

textCmd = &coral.Command{
Expand Down
5 changes: 4 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ func main() {
}

func init() {
coral.OnInitialize(connectOBS)
rootCmd.PersistentFlags().StringVar(&host, "host", "localhost", "host to connect to")
rootCmd.PersistentFlags().StringVar(&password, "password", "", "password for connection")
rootCmd.PersistentFlags().Uint32VarP(&port, "port", "p", 4444, "port to connect to")
Expand All @@ -49,6 +48,10 @@ func getUserAgent() string {
return userAgent
}

func connectOBSCommand(cmd *coral.Command, args []string) {
connectOBS()
}

func connectOBS() {
var err error
client, err = goobs.New(
Expand Down
41 changes: 41 additions & 0 deletions man.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//go:build mango
// +build mango

package main

import (
"fmt"

"github.com/muesli/coral"
mcoral "github.com/muesli/mango-coral"
"github.com/muesli/roff"
)

var (
manCmd = &coral.Command{
Use: "man [directory]",
Short: "Generates manpages",
Long: `Generates manpages in the given directory`,
Hidden: true,
RunE: func(cmd *coral.Command, args []string) error {
return generateManPages()
},
}
)

func init() {
rootCmd.AddCommand(manCmd)
}

func generateManPages() error {
manPage, err := mcoral.NewManPage(1, rootCmd)
if err != nil {
return err
}

manPage = manPage.WithSection("Copyright", "(C) 2022 Christian Muehlhaeuser.\n"+
"Released under MIT license.")

fmt.Println(manPage.Build(roff.NewDocument()))
return nil
}
9 changes: 5 additions & 4 deletions recording.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import (

var (
recordingCmd = &coral.Command{
Use: "recording",
Short: "manage recordings",
Long: `The recording command manages recordings`,
RunE: nil,
Use: "recording",
Short: "manage recordings",
Long: `The recording command manages recordings`,
RunE: nil,
PersistentPreRun: connectOBSCommand,
}

startStopRecordingCmd = &coral.Command{
Expand Down
9 changes: 5 additions & 4 deletions scene.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import (

var (
sceneCmd = &coral.Command{
Use: "scene",
Short: "manage scenes",
Long: `The scene command manages scenes`,
RunE: nil,
Use: "scene",
Short: "manage scenes",
Long: `The scene command manages scenes`,
RunE: nil,
PersistentPreRun: connectOBSCommand,
}

currentSceneCmd = &coral.Command{
Expand Down
9 changes: 5 additions & 4 deletions scenecollection.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import (

var (
sceneCollectionCmd = &coral.Command{
Use: "scenecollection",
Short: "manage scene collections",
Long: `The scenecollection command manages scene collections`,
RunE: nil,
Use: "scenecollection",
Short: "manage scene collections",
Long: `The scenecollection command manages scene collections`,
RunE: nil,
PersistentPreRun: connectOBSCommand,
}

listSceneCollectionCmd = &coral.Command{
Expand Down
9 changes: 5 additions & 4 deletions sceneitems.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import (

var (
sceneItemCmd = &coral.Command{
Use: "sceneitem",
Short: "manage scene items",
Long: `The sceneitem command manages a scene's items`,
RunE: nil,
Use: "sceneitem",
Short: "manage scene items",
Long: `The sceneitem command manages a scene's items`,
RunE: nil,
PersistentPreRun: connectOBSCommand,
}

listSceneItemsCmd = &coral.Command{
Expand Down
9 changes: 5 additions & 4 deletions sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import (

var (
sourceCmd = &coral.Command{
Use: "source",
Short: "manage sources",
Long: `The source command manages sources`,
RunE: nil,
Use: "source",
Short: "manage sources",
Long: `The source command manages sources`,
RunE: nil,
PersistentPreRun: connectOBSCommand,
}

listSourcesCmd = &coral.Command{
Expand Down
9 changes: 5 additions & 4 deletions stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import (

var (
streamCmd = &coral.Command{
Use: "stream",
Short: "manage streams",
Long: `The stream command manages streams`,
RunE: nil,
Use: "stream",
Short: "manage streams",
Long: `The stream command manages streams`,
RunE: nil,
PersistentPreRun: connectOBSCommand,
}

startStopStreamCmd = &coral.Command{
Expand Down
9 changes: 5 additions & 4 deletions studiomode.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import (

var (
studioModeCmd = &coral.Command{
Use: "studiomode",
Short: "manage studio mode",
Long: `The studiomode command manages the studio mode`,
RunE: nil,
Use: "studiomode",
Short: "manage studio mode",
Long: `The studiomode command manages the studio mode`,
RunE: nil,
PersistentPreRun: connectOBSCommand,
}

disableStudioModeCmd = &coral.Command{
Expand Down
9 changes: 5 additions & 4 deletions virtualcam.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import (

var (
virtualCamCmd = &coral.Command{
Use: "virtualcam",
Short: "manage virtual camera",
Long: `The virtualcam command manages the virtual camera`,
RunE: nil,
Use: "virtualcam",
Short: "manage virtual camera",
Long: `The virtualcam command manages the virtual camera`,
RunE: nil,
PersistentPreRun: connectOBSCommand,
}

startStopVirtualCamCmd = &coral.Command{
Expand Down

0 comments on commit 4977212

Please sign in to comment.