@@ -27,26 +27,26 @@ This command generates a markdown formatted document with all the commands, thei
27
27
28
28
var documentationExamples = `
29
29
juju documentation
30
- juju documentation --split
31
- juju documentation --split --no-index --out /tmp/docs
32
-
33
- To render markdown documentation using a list of existing
34
- commands, you can use a file with the following syntax
35
-
36
- command1: id1
37
- command2: id2
38
- commandN: idN
39
-
40
- For example:
41
-
42
- add-cloud: 1183
43
- add-secret: 1284
44
- remove-cloud: 4344
45
-
46
- Then, the urls will be populated using the ids indicated
47
- in the file above.
48
-
49
- juju documentation --split --no-index --out /tmp/docs --discourse-ids /tmp/docs/myids
30
+ juju documentation --split
31
+ juju documentation --split --no-index --out /tmp/docs
32
+
33
+ To render markdown documentation using a list of existing
34
+ commands, you can use a file with the following syntax
35
+
36
+ command1: id1
37
+ command2: id2
38
+ commandN: idN
39
+
40
+ For example:
41
+
42
+ add-cloud: 1183
43
+ add-secret: 1284
44
+ remove-cloud: 4344
45
+
46
+ Then, the urls will be populated using the ids indicated
47
+ in the file above.
48
+
49
+ juju documentation --split --no-index --out /tmp/docs --discourse-ids /tmp/docs/myids
50
50
`
51
51
52
52
type documentationCommand struct {
@@ -473,7 +473,10 @@ func (d *documentationCommand) formatFlags(c Command, info *Info) string {
473
473
c .SetFlags (f )
474
474
}
475
475
476
- // group together all flags for a given value
476
+ // group together all flags for a given value, meaning that flag which sets the same value are
477
+ // grouped together and displayed with the same description, as below:
478
+ //
479
+ // -s, --short, --alternate-string | default value | some description.
477
480
flags := make (map [interface {}]flagsByLength )
478
481
f .VisitAll (func (f * gnuflag.Flag ) {
479
482
flags [f .Value ] = append (flags [f .Value ], f )
@@ -483,6 +486,9 @@ func (d *documentationCommand) formatFlags(c Command, info *Info) string {
483
486
}
484
487
485
488
// sort the output flags by shortest name for each group.
489
+ // Caution: this mean that description/default value displayed in documentation will
490
+ // be the one of the shortest alias. Other will be discarded. Be careful to have the same default
491
+ // values between each alias, and put the description on the shortest alias.
486
492
var byName flagsByName
487
493
for _ , fl := range flags {
488
494
sort .Sort (fl )
@@ -493,14 +499,21 @@ func (d *documentationCommand) formatFlags(c Command, info *Info) string {
493
499
formatted := "| Flag | Default | Usage |\n "
494
500
formatted += "| --- | --- | --- |\n "
495
501
for _ , fs := range byName {
496
- theFlags := ""
502
+ // Collect all flag aliases (usually a short one and a plain one, like -v / --verbose)
503
+ formattedFlags := ""
497
504
for i , f := range fs {
498
505
if i > 0 {
499
- theFlags += ", "
506
+ formattedFlags += ", "
507
+ }
508
+ if len (f .Name ) == 1 {
509
+ formattedFlags += fmt .Sprintf ("`-%s`" , f .Name )
510
+ } else {
511
+ formattedFlags += fmt .Sprintf ("`--%s`" , f .Name )
500
512
}
501
- theFlags += fmt .Sprintf ("`--%s`" , f .Name )
502
513
}
503
- formatted += fmt .Sprintf ("| %s | %s | %s |\n " , theFlags ,
514
+ // display all the flags aliases and the default value and description of the shortest one.
515
+ // Escape Markdown in description in order to display it cleanly in the final documentation.
516
+ formatted += fmt .Sprintf ("| %s | %s | %s |\n " , formattedFlags ,
504
517
EscapeMarkdown (fs [0 ].DefValue ),
505
518
strings .ReplaceAll (EscapeMarkdown (fs [0 ].Usage ), "\n " , " " ),
506
519
)
0 commit comments