Skip to content

Commit

Permalink
add "tink docs" command for markdown and man page generation
Browse files Browse the repository at this point in the history
Signed-off-by: Marques Johansson <[email protected]>
  • Loading branch information
displague committed Aug 28, 2020
1 parent e14ed36 commit f8ef6b0
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 4 deletions.
7 changes: 3 additions & 4 deletions cmd/tink-cli/cmd/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ func completionCmd(name string) *cobra.Command {
# To load completions for each session, execute once:
$ tink-cli completion fish > ~/.config/fish/completions/tink-cli.fish
`,
DisableFlagsInUseLine: true,
Hidden: true,
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
Args: cobra.ExactValidArgs(1),
Hidden: true,
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
Args: cobra.ExactValidArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
switch args[0] {
case "bash":
Expand Down
46 changes: 46 additions & 0 deletions cmd/tink-cli/cmd/docs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package cmd

import (
"fmt"

"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
)

var (
docsPath string
)

// docsCmd returns the generate command that, when run, generates
// documentation
func docsCmd(name string) *cobra.Command {
return &cobra.Command{
Use: "docs [markdown|man]",
Short: "Generate documentation",
Hidden: true,
ValidArgs: []string{"markdown", "man"},
Args: cobra.ExactValidArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
format := args[0]

switch format {
case "markdown":
return doc.GenMarkdownTree(cmd.Parent(), docsPath)
case "man":
header := &doc.GenManHeader{Title: name}
return doc.GenManTree(cmd.Parent(), header, docsPath)
}
// ValidArgs make this error response dead-code
return fmt.Errorf("unknown format: %q", format)
},
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
return nil
},
}
}

func init() {
docsCmd := docsCmd(rootCmd.CalledAs())
docsCmd.Flags().StringVarP(&docsPath, "path", "p", "", "Path where documentation will be generated")
rootCmd.AddCommand(docsCmd)
}
1 change: 1 addition & 0 deletions cmd/tink-cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var rootCmd = &cobra.Command{
Use: "tink",
Short: "tinkerbell CLI",
PersistentPreRunE: setupClient,
DisableAutoGenTag: true,
}

func init() {
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM=
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
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=
Expand Down Expand Up @@ -184,9 +185,11 @@ github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6So
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rollbar/rollbar-go v1.0.2 h1:uA3+z0jq6ka9WUUt9VX/xuiQZXZyWRoeKvkhVvLO9Jc=
github.com/rollbar/rollbar-go v1.0.2/go.mod h1:AcFs5f0I+c71bpHlXNNDbOWJiKwjFDtISeXco0L5PKQ=
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.2.0 h1:juTguoYk5qI21pwyTXY3B3Y5cOTH3ZUyZCg1v/mihuo=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
Expand Down

0 comments on commit f8ef6b0

Please sign in to comment.