Skip to content

Commit

Permalink
add manpage generation (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
bartekpacia authored May 2, 2024
1 parent 5114dcc commit d9198e5
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ config.toml
# build artifacts
/fhome
/fhomed
fhome.1
fhome.2
*.exe

# Generated by HAP
Expand Down
3 changes: 3 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ brews:
description: Interact with smart home devices connected to F&Home
license: MIT
install: |
system("./fhome docs --format man-with-section", :out => ["fhome.1", "w"])
bin.install "fhome"
man1.install "fhome.1"
bash_completion.install "autocomplete/bash_autocomplete_fhome" => "fhome"
zsh_completion.install "autocomplete/zsh_autocomplete_fhome" => "_fhome"
Expand Down
31 changes: 31 additions & 0 deletions cmd/fhomed/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,37 @@ func main() {
Name: "fhomed",
Usage: "Long-running daemon for F&Home Cloud",
EnableBashCompletion: true,
Commands: []*cli.Command{
{
Name: "docs",
Usage: "Print documentation in various formats",
Hidden: true,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "format",
Usage: "output format [markdown, man, or man-with-section]",
Hidden: true,
Value: "markdown",
},
},
Action: func(c *cli.Context) error {
format := c.String("format")
if format == "" || format == "markdown" {
fmt.Println(c.App.ToMarkdown())
return nil
}
if format == "man" {
fmt.Println(c.App.ToMan())
return nil
}
if format == "man-with-section" {
fmt.Println(c.App.ToManWithSection(1))
return nil
}
return fmt.Errorf("invalid format '%s'", format)
},
},
},
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "json",
Expand Down

0 comments on commit d9198e5

Please sign in to comment.