| 1 | package cliscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/ |
| 2 | |
| 3 | import ( |
| 4 | "fmtscip-go gomod github.com/golang/go/src go1.22 fmt/" |
| 5 | "osscip-go gomod github.com/golang/go/src go1.22 os/" |
| 6 | "runtimescip-go gomod github.com/golang/go/src go1.22 runtime/" |
| 7 | "stringsscip-go gomod github.com/golang/go/src go1.22 strings/" |
| 8 | ) |
| 9 | |
| 10 | func prefixForscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/prefixFor().(name string) (prefix string) { |
| 11 | if len(name) == 1 { |
| 12 | prefix = "-" |
| 13 | } else { |
| 14 | prefix = "--" |
| 15 | } |
| 16 | |
| 17 | return prefix |
| 18 | } |
| 19 | |
| 20 | // Returns the placeholder, if any, and the unquoted usage string. |
| 21 | func unquoteUsagescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/unquoteUsage().(usage string) (string, string) { |
| 22 | for i := 0; i < len(usage); i++ { |
| 23 | if usage[i] == '`' { |
| 24 | for j := i + 1; j < len(usage); j++ { |
| 25 | if usage[j] == '`' { |
| 26 | name := usage[i+1 : j] |
| 27 | usage = usage[:i] + name + usage[j+1:] |
| 28 | return name, usage |
| 29 | } |
| 30 | } |
| 31 | break |
| 32 | } |
| 33 | } |
| 34 | return "", usage |
| 35 | } |
| 36 | |
| 37 | func prefixedNamesscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/prefixedNames().(names []string, placeholder string) string { |
| 38 | var prefixed stringsscip-go gomod github.com/golang/go/src go1.22 strings/.Builderscip-go gomod github.com/golang/go/src go1.22 strings/Builder# |
| 39 | for i, name := range names { |
| 40 | if name == "" { |
| 41 | continue |
| 42 | } |
| 43 | |
| 44 | prefixed.WriteStringscip-go gomod github.com/golang/go/src go1.22 strings/Builder#WriteString().(prefixForscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/prefixFor().(name) + name) |
| 45 | if placeholder != "" { |
| 46 | prefixed.WriteStringscip-go gomod github.com/golang/go/src go1.22 strings/Builder#WriteString().(" " + placeholder) |
| 47 | } |
| 48 | if i < len(names)-1 { |
| 49 | prefixed.WriteStringscip-go gomod github.com/golang/go/src go1.22 strings/Builder#WriteString().(", ") |
| 50 | } |
| 51 | } |
| 52 | return prefixed.Stringscip-go gomod github.com/golang/go/src go1.22 strings/Builder#String().() |
| 53 | } |
| 54 | |
| 55 | func envFormatscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/envFormat().(envVars []string, prefix, sep, suffix string) string { |
| 56 | if len(envVars) > 0 { |
| 57 | return fmtscip-go gomod github.com/golang/go/src go1.22 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.22 fmt/Sprintf().(" [%s%s%s]", prefix, stringsscip-go gomod github.com/golang/go/src go1.22 strings/.Joinscip-go gomod github.com/golang/go/src go1.22 strings/Join().(envVars, sep), suffix) |
| 58 | } |
| 59 | return "" |
| 60 | } |
| 61 | |
| 62 | func defaultEnvFormatscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/defaultEnvFormat().(envVars []string) string { |
| 63 | return envFormatscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/envFormat().(envVars, "$", ", $", "") |
| 64 | } |
| 65 | |
| 66 | func withEnvHintscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/withEnvHint().(envVars []string, str string) string { |
| 67 | envText := "" |
| 68 | if runtimescip-go gomod github.com/golang/go/src go1.22 runtime/.GOOSscip-go gomod github.com/golang/go/src go1.22 runtime/GOOS. != "windows" || osscip-go gomod github.com/golang/go/src go1.22 os/.Getenvscip-go gomod github.com/golang/go/src go1.22 os/Getenv().("PSHOME") != "" { |
| 69 | envText = defaultEnvFormatscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/defaultEnvFormat().(envVars) |
| 70 | } else { |
| 71 | envText = envFormatscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/envFormat().(envVars, "%", "%, %", "%") |
| 72 | } |
| 73 | return str + envText |
| 74 | } |
| 75 | |
| 76 | func withFileHintscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/withFileHint().(filePath, str string) string { |
| 77 | fileText := "" |
| 78 | if filePath != "" { |
| 79 | fileText = fmtscip-go gomod github.com/golang/go/src go1.22 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.22 fmt/Sprintf().(" [%s]", filePath) |
| 80 | } |
| 81 | return str + fileText |
| 82 | } |
| 83 | |
| 84 | func formatDefaultscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/formatDefault().(format string) string { |
| 85 | return " (default: " + format + ")" |
| 86 | } |
| 87 | |
| 88 | func stringifyFlagscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/stringifyFlag().(f Flagscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Flag#) string { |
| 89 | // enforce DocGeneration interface on flags to avoid reflection |
| 90 | df, ok := f.(DocGenerationFlagscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/DocGenerationFlag#) |
| 91 | if !ok { |
| 92 | return "" |
| 93 | } |
| 94 | placeholder, usage := unquoteUsagescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/unquoteUsage().(df.GetUsagescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/DocGenerationFlag#GetUsage.()) |
| 95 | needsPlaceholder := df.TakesValuescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/DocGenerationFlag#TakesValue.() |
| 96 | // if needsPlaceholder is true, placeholder is empty |
| 97 | if needsPlaceholder && placeholder == "" { |
| 98 | // try to get type from flag |
| 99 | if tname := df.TypeNamescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/DocGenerationFlag#TypeName.(); tname != "" { |
| 100 | placeholder = tname |
| 101 | } else { |
| 102 | placeholder = defaultPlaceholderscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/defaultPlaceholder. |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | defaultValueString := "" |
| 107 | |
| 108 | // don't print default text for required flags |
| 109 | if rf, ok := f.(RequiredFlagscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/RequiredFlag#); !ok || !rf.IsRequiredscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/RequiredFlag#IsRequired.() { |
| 110 | if df.IsDefaultVisiblescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/DocGenerationFlag#IsDefaultVisible.() { |
| 111 | if s := df.GetDefaultTextscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/DocGenerationFlag#GetDefaultText.(); s != "" { |
| 112 | defaultValueString = fmtscip-go gomod github.com/golang/go/src go1.22 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.22 fmt/Sprintf().(formatDefaultscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/formatDefault().("%s"), s) |
| 113 | } else if df.TakesValuescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/DocGenerationFlag#TakesValue.() && df.GetValuescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/DocGenerationFlag#GetValue.() != "" { |
| 114 | defaultValueString = fmtscip-go gomod github.com/golang/go/src go1.22 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.22 fmt/Sprintf().(formatDefaultscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/formatDefault().("%s"), df.GetValuescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/DocGenerationFlag#GetValue.()) |
| 115 | } |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | usageWithDefault := stringsscip-go gomod github.com/golang/go/src go1.22 strings/.TrimSpacescip-go gomod github.com/golang/go/src go1.22 strings/TrimSpace().(usage + defaultValueString) |
| 120 | |
| 121 | pn := prefixedNamesscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/prefixedNames().(f.Namesscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Flag#Names.(), placeholder) |
| 122 | sliceFlag, ok := f.(DocGenerationMultiValueFlagscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/DocGenerationMultiValueFlag#) |
| 123 | if ok && sliceFlag.IsMultiValueFlagscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/DocGenerationMultiValueFlag#IsMultiValueFlag.() { |
| 124 | pn = pn + " [ " + pn + " ]" |
| 125 | } |
| 126 | |
| 127 | return withEnvHintscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/withEnvHint().(df.GetEnvVarsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/DocGenerationFlag#GetEnvVars.(), fmtscip-go gomod github.com/golang/go/src go1.22 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.22 fmt/Sprintf().("%s\t%s", pn, usageWithDefault)) |
| 128 | } |