Skip to content

Commit

Permalink
Merge pull request #101 from barrettj12/no-options
Browse files Browse the repository at this point in the history
[documentation command] don't print options table if no flags
  • Loading branch information
barrettj12 authored Jul 17, 2023
2 parents 5d2ea2e + 1e7259f commit 838ea76
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions documentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,9 @@ func (d *documentationCommand) formatFlags(c Command, info *Info) string {
f.VisitAll(func(f *gnuflag.Flag) {
flags[f.Value] = append(flags[f.Value], f)
})
if len(flags) == 0 {
return ""
}

// sort the output flags by shortest name for each group.
var byName flagsByName
Expand Down
31 changes: 31 additions & 0 deletions documentation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func (s *documentationSuite) TestFormatCommand(c *gc.C) {
title bool
expected string
}{{
// "smoke test" - just a regular command
command: &docTestCommand{
info: &cmd.Info{
Name: "add-cloud",
Expand Down Expand Up @@ -56,6 +57,36 @@ details for add-cloud...
---
`)[1:],
}, {
// no flags - don't print "Options" table
command: &docTestCommand{
info: &cmd.Info{
Name: "foo",
Args: "<args>",
Purpose: "insert summary here...",
Doc: "insert details here...",
Examples: "insert examples here...",
},
flags: []string{},
},
title: false,
expected: (`
## Summary
insert summary here...
## Usage
` + "```" + `juju foo [options] <args>` + "```" + `
## Examples
insert examples here...
## Details
insert details here...
---
`)[1:],
}}

Expand Down

0 comments on commit 838ea76

Please sign in to comment.