Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a hidden docs command #8

Merged
merged 1 commit into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ brews:
description: Handy mini-CLI for more pleasant work with Android Emulator
license: MIT
install: |
man_content = `./emu docs --format man-with-section`
File.write("emu.1", man_content)

bin.install "emu"
man1.install "emu.1"
bash_completion.install "autocomplete/bash_autocomplete" => "emu"
zsh_completion.install "autocomplete/zsh_autocomplete" => "_emu"

Expand Down
43 changes: 43 additions & 0 deletions cmd/emu/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"syscall"

emulator "github.com/bartekpacia/emu"
docs "github.com/urfave/cli-docs/v3"
"github.com/urfave/cli/v3"
)

Expand Down Expand Up @@ -46,6 +47,8 @@ func main() {
&runCommand,
&listCommand,
&killCommand,
// docs
&printDocsCommand,
},
CommandNotFound: func(ctx context.Context, c *cli.Command, command string) {
log.Printf("invalid command '%s'. See 'emu --help'\n", command)
Expand Down Expand Up @@ -323,3 +326,43 @@ var animationsCommand = cli.Command{
},
},
}

var printDocsCommand = 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.Root())
if err != nil {
return fmt.Errorf("generate documentation in markdown: %v", err)
}
fmt.Println(content)
case "man":
content, err := docs.ToMan(cmd.Root())
if err != nil {
return fmt.Errorf("generate documentation in man: %v", err)
}
fmt.Println(content)
case "man-with-section":
content, err := docs.ToManWithSection(cmd.Root(), 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
},
}
10 changes: 9 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,12 @@ module github.com/bartekpacia/emu

go 1.23

require github.com/urfave/cli/v3 v3.0.0-alpha9.2
require (
github.com/urfave/cli-docs/v3 v3.0.0-alpha6
github.com/urfave/cli/v3 v3.0.0-alpha9.4
)

require (
github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
)
10 changes: 8 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
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.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
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/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/urfave/cli/v3 v3.0.0-alpha9.1 h1:1fJU+bltkwN8lF4Sni/X0i1d8XwPIrS82ivZ8qsp/q4=
github.com/urfave/cli/v3 v3.0.0-alpha9.1/go.mod h1:FnIeEMYu+ko8zP1F9Ypr3xkZMIDqW3DR92yUtY39q1Y=
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.2 h1:CL8llQj3dGRLVQQzHxS+ZYRLanOuhyK1fXgLKD+qV+Y=
github.com/urfave/cli/v3 v3.0.0-alpha9.2/go.mod h1:FnIeEMYu+ko8zP1F9Ypr3xkZMIDqW3DR92yUtY39q1Y=
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=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=