PrintDefaults is modified from the flag package to control the order of printing
(fs *flag.FlagSet)
| 109 | |
| 110 | // PrintDefaults is modified from the flag package to control the order of printing |
| 111 | func PrintDefaults(fs *flag.FlagSet) { |
| 112 | helpOrder := []string{ |
| 113 | configParam, |
| 114 | dataDirParam, |
| 115 | configHelpFlag, |
| 116 | versionFlag, |
| 117 | chdirParam, |
| 118 | stdInParam, |
| 119 | stdOutParam, |
| 120 | stdErrParam, |
| 121 | stdOutAndErrParam, |
| 122 | } |
| 123 | |
| 124 | for _, fName := range helpOrder { |
| 125 | f := fs.Lookup(fName) |
| 126 | var b strings.Builder |
| 127 | fmt.Fprintf(&b, " -%s", f.Name) // Two spaces before -; see next two comments. |
| 128 | name, usage := flag.UnquoteUsage(f) |
| 129 | if len(name) > 0 { |
| 130 | b.WriteString(" ") |
| 131 | b.WriteString(name) |
| 132 | } |
| 133 | // Boolean flags of one ASCII letter are so common we |
| 134 | // treat them specially, putting their usage on the same line. |
| 135 | if b.Len() <= 4 { // space, space, '-', 'x'. |
| 136 | b.WriteString("\t") |
| 137 | } else { |
| 138 | // Four spaces before the tab triggers good alignment |
| 139 | // for both 4- and 8-space tab stops. |
| 140 | b.WriteString("\n \t") |
| 141 | } |
| 142 | // wrap at 80 chars |
| 143 | usage = wordwrap.WrapString(usage, 76) |
| 144 | b.WriteString(strings.ReplaceAll(usage, "\n", "\n \t")) |
| 145 | |
| 146 | if f.DefValue != "false" && f.DefValue != "" { |
| 147 | fmt.Fprintf(&b, " (default %v)", f.DefValue) |
| 148 | } |
| 149 | fmt.Fprint(fs.Output(), b.String(), "\n") |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | func main() { |
| 154 | args := os.Args[1:] |
no test coverage detected