-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add "tink docs" command for markdown and man page generation
Signed-off-by: Marques Johansson <[email protected]>
- Loading branch information
Showing
4 changed files
with
53 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters