@@ -105,3 +105,59 @@ func (*markdownSuite) TestOutput(c *gc.C) {
105
105
c .Assert (err , jc .ErrorIsNil )
106
106
c .Check (buf .String (), gc .Equals , string (expected ))
107
107
}
108
+
109
+ // TestOutputWithoutArgs tests that the output of the PrintMarkdown function is
110
+ // correct when a command does not need arguments, e.g. list commands.
111
+ func (* markdownSuite ) TestOutputWithoutArgs (c * gc.C ) {
112
+ seeAlso := []string {"add-cloud" , "update-cloud" , "remove-cloud" , "update-credential" }
113
+ subcommands := map [string ]string {
114
+ "foo" : "foo the bar baz" ,
115
+ "bar" : "bar the baz foo" ,
116
+ "baz" : "baz the foo bar" ,
117
+ }
118
+
119
+ command := & docTestCommand {
120
+ info : & cmd.Info {
121
+ Name : "clouds" ,
122
+ Args : "" , //Empty args should still result in a usage field.
123
+ Purpose : "List clouds." ,
124
+ Doc : "details for clouds..." ,
125
+ Examples : "examples for clouds..." ,
126
+ SeeAlso : seeAlso ,
127
+ Aliases : []string {"list-clouds" },
128
+ Subcommands : subcommands ,
129
+ },
130
+ }
131
+
132
+ // These functions verify the provided argument is in the expected set.
133
+ linkForCommand := func (s string ) string {
134
+ for _ , cmd := range seeAlso {
135
+ if cmd == s {
136
+ return "https://docs.com/" + cmd
137
+ }
138
+ }
139
+ c .Fatalf ("linkForCommand called with unexpected command %q" , s )
140
+ return ""
141
+ }
142
+
143
+ linkForSubcommand := func (s string ) string {
144
+ _ , ok := subcommands [s ]
145
+ if ! ok {
146
+ c .Fatalf ("linkForSubcommand called with unexpected subcommand %q" , s )
147
+ }
148
+ return "https://docs.com/clouds/" + s
149
+ }
150
+
151
+ expected , err := os .ReadFile ("testdata/list-clouds.md" )
152
+ c .Assert (err , jc .ErrorIsNil )
153
+
154
+ var buf bytes.Buffer
155
+ err = cmd .PrintMarkdown (& buf , command , cmd.MarkdownOptions {
156
+ Title : `Command "juju clouds"` ,
157
+ UsagePrefix : "juju " ,
158
+ LinkForCommand : linkForCommand ,
159
+ LinkForSubcommand : linkForSubcommand ,
160
+ })
161
+ c .Assert (err , jc .ErrorIsNil )
162
+ c .Check (buf .String (), gc .Equals , string (expected ))
163
+ }
0 commit comments