Skip to content

Commit

Permalink
Update usage and long help for command.
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Witkowski committed Sep 18, 2023
1 parent 07877ab commit cc48f79
Showing 1 changed file with 41 additions and 26 deletions.
67 changes: 41 additions & 26 deletions cmd/provenanced/cmd/docgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,53 +20,68 @@ const (

func GetDocGenCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "docgen",
Short: "Generates cli documentation for the Provenance Blockchain.",
Long: "",
Use: "docgen <target directory> (--markdown) (--yaml) (--rest) (--manpages) [flags]",
Short: "Generates cli documentation for the Provenance Blockchain.",
Long: `Generates cli documentation for the Provenance Blockchain.
Various documentation formats can be generated, including markdown, YAML, REST, and man pages.
To ensure the command's success, you must specify at least one format.
A successful command will not only generate files in the selected formats but also create the target directory if it doesn't already exist.`,
Example: fmt.Sprintf("%s '/tmp' --yaml --markdown", docGenCmdStart),
Hidden: true,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
dir := args[0]
if !exists(dir) {
err := os.Mkdir(dir, 0755)
if err != nil {
return err
}
}

// Check if at least one flag is enabled

markdown, err := cmd.Flags().GetBool(FlagMarkdown)
if err != nil {
return err
}
if markdown {
doc.GenMarkdownTree(cmd.Root(), dir)
}

yaml, err := cmd.Flags().GetBool(FlagYaml)
if err != nil {
return err
}
if yaml {
doc.GenYamlTree(cmd.Root(), dir)
}

rest, err := cmd.Flags().GetBool(FlagRest)
if err != nil {
return err
}
if rest {
doc.GenReSTTree(cmd.Root(), dir)
}

manpage, err := cmd.Flags().GetBool(FlagManpage)
if err != nil {
return err
}

if !markdown && !yaml && !rest && !manpage {
return fmt.Errorf("at least one doc type must be specified.")
}

dir := args[0]
if !exists(dir) {
err := os.Mkdir(dir, 0755)
if err != nil {
return err
}
}

if markdown {
err = doc.GenMarkdownTree(cmd.Root(), dir)
if err != nil {
return err
}
}
if yaml {
err = doc.GenYamlTree(cmd.Root(), dir)
if err != nil {
return err
}
}
if rest {
err = doc.GenReSTTree(cmd.Root(), dir)
if err != nil {
return err
}
}
if manpage {
doc.GenManTree(cmd.Root(), nil, dir)
err = doc.GenManTree(cmd.Root(), nil, dir)
if err != nil {
return err
}
}

return nil
Expand Down

0 comments on commit cc48f79

Please sign in to comment.