Skip to content

Commit

Permalink
readd docs
Browse files Browse the repository at this point in the history
  • Loading branch information
bartekpacia committed Nov 23, 2024
1 parent 0375996 commit 7a8c6d8
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ brews:
description: Background daemon for F&Home
license: MIT
install: |
man_content = `./fhomed docs --format man-with-section`
File.write("fhomed.1", man_content)
bin.install "fhomed"
man1.install "fhomed.1"
bash_completion.install "autocomplete/bash_autocomplete_fhomed" => "fhomed"
zsh_completion.install "autocomplete/zsh_autocomplete_fhomed" => "_fhomed"
Expand Down
42 changes: 42 additions & 0 deletions cmd/fhomed/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/knadh/koanf/parsers/toml"
"github.com/knadh/koanf/providers/file"
"github.com/lmittmann/tint"
docs "github.com/urfave/cli-docs/v3"
"github.com/urfave/cli/v3"
)

Expand All @@ -32,6 +33,47 @@ func main() {
"Bartek Pacia <barpac02@gmail.com>",
},
EnableShellCompletion: 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(ctx context.Context, cmd *cli.Command) error {
format := cmd.String("format")
switch format {
case "", "markdown":
content, err := docs.ToMarkdown(cmd)
if err != nil {
return fmt.Errorf("generate documentation in markdown: %v", err)
}
fmt.Println(content)
case "man":
content, err := docs.ToMan(cmd)
if err != nil {
return fmt.Errorf("generate documentation in man: %v", err)
}
fmt.Println(content)
case "man-with-section":
content, err := docs.ToManWithSection(cmd, 1)
if err != nil {
return fmt.Errorf("generate documentation in man with section 1: %v", err)
}
fmt.Println(content)
default:
return fmt.Errorf("invalid documentation format %#v", format)
}
return nil
},
},
},
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "json",
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@ require (
github.com/gorilla/websocket v1.5.3
github.com/knadh/koanf v1.5.0
github.com/lmittmann/tint v1.0.5
github.com/urfave/cli-docs/v3 v3.0.0-alpha6
github.com/urfave/cli/v3 v3.0.0-alpha9.4
golang.org/x/crypto v0.29.0
)

require (
github.com/brutella/dnssd v1.2.14 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect
github.com/fsnotify/fsnotify v1.8.0 // indirect
github.com/go-chi/chi v1.5.5 // indirect
github.com/miekg/dns v1.1.62 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/tadglines/go-pkgs v0.0.0-20210623144937-b983b20f54f9 // indirect
github.com/vishvananda/netlink v1.3.0 // indirect
github.com/vishvananda/netns v0.0.5 // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGX
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/cpuguy83/go-md2man/v2 v2.0.5 h1:ZtcqGrnekaHpVLArFSe4HK5DoKx1T0rq2DwVB0alcyc=
github.com/cpuguy83/go-md2man/v2 v2.0.5/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -230,6 +232,8 @@ github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4O
github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
github.com/rhnvrm/simples3 v0.6.1/go.mod h1:Y+3vYm2V7Y4VijFoJHHTrja6OgPrJ2cBti8dPGkC3sA=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc=
Expand All @@ -256,6 +260,8 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tadglines/go-pkgs v0.0.0-20210623144937-b983b20f54f9 h1:aeN+ghOV0b2VCmKKO3gqnDQ8mLbpABZgRR2FVYx4ouI=
github.com/tadglines/go-pkgs v0.0.0-20210623144937-b983b20f54f9/go.mod h1:roo6cZ/uqpwKMuvPG0YmzI5+AmUiMWfjCBZpGXqbTxE=
github.com/urfave/cli-docs/v3 v3.0.0-alpha6 h1:w/l/N0xw1rO/aHRIGXJ0lDwwYFOzilup1qGvIytP3BI=
github.com/urfave/cli-docs/v3 v3.0.0-alpha6/go.mod h1:p7Z4lg8FSTrPB9GTaNyTrK3ygffHZcK3w0cU2VE+mzU=
github.com/urfave/cli/v3 v3.0.0-alpha9.4 h1:KSI7yzEtZP5vvRhQHCxsoZaqohITu8tnLbx+VNJLSrs=
github.com/urfave/cli/v3 v3.0.0-alpha9.4/go.mod h1:FnIeEMYu+ko8zP1F9Ypr3xkZMIDqW3DR92yUtY39q1Y=
github.com/vishvananda/netlink v1.2.1-beta.2/go.mod h1:twkDnbuQxJYemMlGd4JFIcuhgX83tXhKS2B/PRMpOho=
Expand Down

0 comments on commit 7a8c6d8

Please sign in to comment.