| 1 |
package cli |
| 2 |
|
| 3 |
var helpNameTemplate = `{{$v := offset .HelpName 6}}{{wrap .HelpName 3}}{{if .Usage}} - {{wrap .Usage $v}}{{end}}` |
| 4 |
var usageTemplate = `{{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.HelpName}}{{if .VisibleFlags}} [command options]{{end}}{{if .ArgsUsage}} {{.ArgsUsage}}{{else}}{{if .Args}} [arguments...]{{end}}{{end}}{{end}}` |
| 5 |
var descriptionTemplate = `{{wrap .Description 3}}` |
| 6 |
var authorsTemplate = `{{with $length := len .Authors}}{{if ne 1 $length}}S{{end}}{{end}}: |
| 7 |
{{range $index, $author := .Authors}}{{if $index}} |
| 8 |
{{end}}{{$author}}{{end}}` |
| 9 |
var visibleCommandTemplate = `{{ $cv := offsetCommands .VisibleCommands 5}}{{range .VisibleCommands}} |
| 10 |
{{$s := join .Names ", "}}{{$s}}{{ $sp := subtract $cv (offset $s 3) }}{{ indent $sp ""}}{{wrap .Usage $cv}}{{end}}` |
| 11 |
var visibleCommandCategoryTemplate = `{{range .VisibleCategories}}{{if .Name}} |
| 12 |
{{.Name}}:{{range .VisibleCommands}} |
| 13 |
{{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{else}}{{template "visibleCommandTemplate" .}}{{end}}{{end}}` |
| 14 |
var visibleFlagCategoryTemplate = `{{range .VisibleFlagCategories}} |
| 15 |
{{if .Name}}{{.Name}} |
| 16 |
|
| 17 |
{{end}}{{$flglen := len .Flags}}{{range $i, $e := .Flags}}{{if eq (subtract $flglen $i) 1}}{{$e}} |
| 18 |
{{else}}{{$e}} |
| 19 |
{{end}}{{end}}{{end}}` |
| 20 |
|
| 21 |
var visibleFlagTemplate = `{{range $i, $e := .VisibleFlags}} |
| 22 |
{{wrap $e.String 6}}{{end}}` |
| 23 |
|
| 24 |
var versionTemplate = `{{if .Version}}{{if not .HideVersion}} |
| 25 |
|
| 26 |
VERSION: |
| 27 |
{{.Version}}{{end}}{{end}}` |
| 28 |
|
| 29 |
var copyrightTemplate = `{{wrap .Copyright 3}}` |
| 30 |
|
| 31 |
// AppHelpTemplate is the text template for the Default help topic. |
| 32 |
// cli.go uses text/template to render templates. You can |
| 33 |
// render custom help text by setting this variable. |
| 34 |
var AppHelpTemplate = `NAME: |
| 35 |
{{template "helpNameTemplate" .}} |
| 36 |
|
| 37 |
USAGE: |
| 38 |
{{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.HelpName}} {{if .VisibleFlags}}[global options]{{end}}{{if .Commands}} command [command options]{{end}}{{if .ArgsUsage}} {{.ArgsUsage}}{{else}}{{if .Args}} [arguments...]{{end}}{{end}}{{end}}{{if .Version}}{{if not .HideVersion}} |
| 39 |
|
| 40 |
VERSION: |
| 41 |
{{.Version}}{{end}}{{end}}{{if .Description}} |
| 42 |
|
| 43 |
DESCRIPTION: |
| 44 |
{{template "descriptionTemplate" .}}{{end}} |
| 45 |
{{- if len .Authors}} |
| 46 |
|
| 47 |
AUTHOR{{template "authorsTemplate" .}}{{end}}{{if .VisibleCommands}} |
| 48 |
|
| 49 |
COMMANDS:{{template "visibleCommandCategoryTemplate" .}}{{end}}{{if .VisibleFlagCategories}} |
| 50 |
|
| 51 |
GLOBAL OPTIONS:{{template "visibleFlagCategoryTemplate" .}}{{else if .VisibleFlags}} |
| 52 |
|
| 53 |
GLOBAL OPTIONS:{{template "visibleFlagTemplate" .}}{{end}}{{if .Copyright}} |
| 54 |
|
| 55 |
COPYRIGHT: |
| 56 |
{{template "copyrightTemplate" .}}{{end}} |
| 57 |
` |
| 58 |
|
| 59 |
// CommandHelpTemplate is the text template for the command help topic. |
| 60 |
// cli.go uses text/template to render templates. You can |
| 61 |
// render custom help text by setting this variable. |
| 62 |
var CommandHelpTemplate = `NAME: |
| 63 |
{{template "helpNameTemplate" .}} |
| 64 |
|
| 65 |
USAGE: |
| 66 |
{{template "usageTemplate" .}}{{if .Category}} |
| 67 |
|
| 68 |
CATEGORY: |
| 69 |
{{.Category}}{{end}}{{if .Description}} |
| 70 |
|
| 71 |
DESCRIPTION: |
| 72 |
{{template "descriptionTemplate" .}}{{end}}{{if .VisibleFlagCategories}} |
| 73 |
|
| 74 |
OPTIONS:{{template "visibleFlagCategoryTemplate" .}}{{else if .VisibleFlags}} |
| 75 |
|
| 76 |
OPTIONS:{{template "visibleFlagTemplate" .}}{{end}} |
| 77 |
` |
| 78 |
|
| 79 |
// SubcommandHelpTemplate is the text template for the subcommand help topic. |
| 80 |
// cli.go uses text/template to render templates. You can |
| 81 |
// render custom help text by setting this variable. |
| 82 |
var SubcommandHelpTemplate = `NAME: |
| 83 |
{{template "helpNameTemplate" .}} |
| 84 |
|
| 85 |
USAGE: |
| 86 |
{{template "usageTemplate" .}}{{if .Category}} |
| 87 |
|
| 88 |
CATEGORY: |
| 89 |
{{.Category}}{{end}}{{if .Description}} |
| 90 |
|
| 91 |
DESCRIPTION: |
| 92 |
{{template "descriptionTemplate" .}}{{end}}{{if .VisibleCommands}} |
| 93 |
|
| 94 |
COMMANDS:{{template "visibleCommandCategoryTemplate" .}}{{end}}{{if .VisibleFlagCategories}} |
| 95 |
|
| 96 |
OPTIONS:{{template "visibleFlagCategoryTemplate" .}}{{else if .VisibleFlags}} |
| 97 |
|
| 98 |
OPTIONS:{{template "visibleFlagTemplate" .}}{{end}} |
| 99 |
` |
| 100 |
|
| 101 |
var MarkdownDocTemplate = `{{if gt .SectionNum 0}}% {{ .App.Name }} {{ .SectionNum }} |
| 102 |
|
| 103 |
{{end}}# NAME |
| 104 |
|
| 105 |
{{ .App.Name }}{{ if .App.Usage }} - {{ .App.Usage }}{{ end }} |
| 106 |
|
| 107 |
# SYNOPSIS |
| 108 |
|
| 109 |
{{ .App.Name }} |
| 110 |
{{ if .SynopsisArgs }} |
| 111 |
` + "```" + ` |
| 112 |
{{ range $v := .SynopsisArgs }}{{ $v }}{{ end }}` + "```" + ` |
| 113 |
{{ end }}{{ if .App.Description }} |
| 114 |
# DESCRIPTION |
| 115 |
|
| 116 |
{{ .App.Description }} |
| 117 |
{{ end }} |
| 118 |
**Usage**: |
| 119 |
|
| 120 |
` + "```" + `{{ if .App.UsageText }} |
| 121 |
{{ .App.UsageText }} |
| 122 |
{{ else }} |
| 123 |
{{ .App.Name }} [GLOBAL OPTIONS] command [COMMAND OPTIONS] [ARGUMENTS...] |
| 124 |
{{ end }}` + "```" + ` |
| 125 |
{{ if .GlobalArgs }} |
| 126 |
# GLOBAL OPTIONS |
| 127 |
{{ range $v := .GlobalArgs }} |
| 128 |
{{ $v }}{{ end }} |
| 129 |
{{ end }}{{ if .Commands }} |
| 130 |
# COMMANDS |
| 131 |
{{ range $v := .Commands }} |
| 132 |
{{ $v }}{{ end }}{{ end }}` |
| 133 |
|
| 134 |
var FishCompletionTemplate = `# {{ .App.Name }} fish shell completion |
| 135 |
|
| 136 |
function __fish_{{ .App.Name }}_no_subcommand --description 'Test if there has been any subcommand yet' |
| 137 |
for i in (commandline -opc) |
| 138 |
if contains -- $i{{ range $v := .AllCommands }} {{ $v }}{{ end }} |
| 139 |
return 1 |
| 140 |
end |
| 141 |
end |
| 142 |
return 0 |
| 143 |
end |
| 144 |
|
| 145 |
{{ range $v := .Completions }}{{ $v }} |
| 146 |
{{ end }}` |