status-go/vendor/github.com/urfave/cli/v2/template.go

144 lines
5.0 KiB
Go
Raw Permalink Normal View History

2022-10-25 14:25:08 +00:00
package cli
2022-11-04 13:57:20 +00:00
var helpNameTemplate = `{{$v := offset .HelpName 6}}{{wrap .HelpName 3}}{{if .Usage}} - {{wrap .Usage $v}}{{end}}`
2024-05-15 23:15:00 +00:00
var usageTemplate = `{{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.HelpName}}{{if .VisibleFlags}} [command options]{{end}}{{if .ArgsUsage}}{{.ArgsUsage}}{{else}}{{if .Args}} [arguments...]{{end}}{{end}}{{end}}`
2022-11-04 13:57:20 +00:00
var descriptionTemplate = `{{wrap .Description 3}}`
var authorsTemplate = `{{with $length := len .Authors}}{{if ne 1 $length}}S{{end}}{{end}}:
{{range $index, $author := .Authors}}{{if $index}}
{{end}}{{$author}}{{end}}`
var visibleCommandTemplate = `{{ $cv := offsetCommands .VisibleCommands 5}}{{range .VisibleCommands}}
{{$s := join .Names ", "}}{{$s}}{{ $sp := subtract $cv (offset $s 3) }}{{ indent $sp ""}}{{wrap .Usage $cv}}{{end}}`
var visibleCommandCategoryTemplate = `{{range .VisibleCategories}}{{if .Name}}
{{.Name}}:{{range .VisibleCommands}}
{{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{else}}{{template "visibleCommandTemplate" .}}{{end}}{{end}}`
var visibleFlagCategoryTemplate = `{{range .VisibleFlagCategories}}
{{if .Name}}{{.Name}}
{{end}}{{$flglen := len .Flags}}{{range $i, $e := .Flags}}{{if eq (subtract $flglen $i) 1}}{{$e}}
{{else}}{{$e}}
{{end}}{{end}}{{end}}`
var visibleFlagTemplate = `{{range $i, $e := .VisibleFlags}}
{{wrap $e.String 6}}{{end}}`
var versionTemplate = `{{if .Version}}{{if not .HideVersion}}
VERSION:
{{.Version}}{{end}}{{end}}`
var copyrightTemplate = `{{wrap .Copyright 3}}`
2022-10-25 14:25:08 +00:00
// AppHelpTemplate is the text template for the Default help topic.
// cli.go uses text/template to render templates. You can
// render custom help text by setting this variable.
var AppHelpTemplate = `NAME:
2022-11-04 13:57:20 +00:00
{{template "helpNameTemplate" .}}
2022-10-25 14:25:08 +00:00
USAGE:
2024-05-15 23:15:00 +00:00
{{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}}
2022-10-25 14:25:08 +00:00
VERSION:
{{.Version}}{{end}}{{end}}{{if .Description}}
DESCRIPTION:
2022-11-04 13:57:20 +00:00
{{template "descriptionTemplate" .}}{{end}}
{{- if len .Authors}}
2022-10-25 14:25:08 +00:00
2022-11-04 13:57:20 +00:00
AUTHOR{{template "authorsTemplate" .}}{{end}}{{if .VisibleCommands}}
2022-10-25 14:25:08 +00:00
2022-11-04 13:57:20 +00:00
COMMANDS:{{template "visibleCommandCategoryTemplate" .}}{{end}}{{if .VisibleFlagCategories}}
2022-10-25 14:25:08 +00:00
2022-11-04 13:57:20 +00:00
GLOBAL OPTIONS:{{template "visibleFlagCategoryTemplate" .}}{{else if .VisibleFlags}}
2022-10-25 14:25:08 +00:00
2022-11-04 13:57:20 +00:00
GLOBAL OPTIONS:{{template "visibleFlagTemplate" .}}{{end}}{{if .Copyright}}
2022-10-25 14:25:08 +00:00
COPYRIGHT:
2022-11-04 13:57:20 +00:00
{{template "copyrightTemplate" .}}{{end}}
2022-10-25 14:25:08 +00:00
`
// CommandHelpTemplate is the text template for the command help topic.
// cli.go uses text/template to render templates. You can
// render custom help text by setting this variable.
var CommandHelpTemplate = `NAME:
2022-11-04 13:57:20 +00:00
{{template "helpNameTemplate" .}}
2022-10-25 14:25:08 +00:00
USAGE:
2022-11-04 13:57:20 +00:00
{{template "usageTemplate" .}}{{if .Category}}
2022-10-25 14:25:08 +00:00
CATEGORY:
{{.Category}}{{end}}{{if .Description}}
DESCRIPTION:
2022-11-04 13:57:20 +00:00
{{template "descriptionTemplate" .}}{{end}}{{if .VisibleFlagCategories}}
2022-10-25 14:25:08 +00:00
2022-11-04 13:57:20 +00:00
OPTIONS:{{template "visibleFlagCategoryTemplate" .}}{{else if .VisibleFlags}}
2022-10-25 14:25:08 +00:00
2022-11-04 13:57:20 +00:00
OPTIONS:{{template "visibleFlagTemplate" .}}{{end}}
2022-10-25 14:25:08 +00:00
`
// SubcommandHelpTemplate is the text template for the subcommand help topic.
// cli.go uses text/template to render templates. You can
// render custom help text by setting this variable.
var SubcommandHelpTemplate = `NAME:
2022-11-04 13:57:20 +00:00
{{template "helpNameTemplate" .}}
2022-10-25 14:25:08 +00:00
USAGE:
2024-05-15 23:15:00 +00:00
{{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.HelpName}} {{if .VisibleFlags}}command [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}{{if .Args}}[arguments...]{{end}}{{end}}{{end}}{{if .Description}}
2022-10-25 14:25:08 +00:00
DESCRIPTION:
2022-11-04 13:57:20 +00:00
{{template "descriptionTemplate" .}}{{end}}{{if .VisibleCommands}}
2022-10-25 14:25:08 +00:00
2024-05-15 23:15:00 +00:00
COMMANDS:{{template "visibleCommandCategoryTemplate" .}}{{end}}{{if .VisibleFlagCategories}}
2022-11-04 13:57:20 +00:00
OPTIONS:{{template "visibleFlagCategoryTemplate" .}}{{else if .VisibleFlags}}
2022-10-25 14:25:08 +00:00
2022-11-04 13:57:20 +00:00
OPTIONS:{{template "visibleFlagTemplate" .}}{{end}}
2022-10-25 14:25:08 +00:00
`
var MarkdownDocTemplate = `{{if gt .SectionNum 0}}% {{ .App.Name }} {{ .SectionNum }}
{{end}}# NAME
{{ .App.Name }}{{ if .App.Usage }} - {{ .App.Usage }}{{ end }}
# SYNOPSIS
{{ .App.Name }}
{{ if .SynopsisArgs }}
` + "```" + `
{{ range $v := .SynopsisArgs }}{{ $v }}{{ end }}` + "```" + `
{{ end }}{{ if .App.Description }}
# DESCRIPTION
{{ .App.Description }}
{{ end }}
**Usage**:
` + "```" + `{{ if .App.UsageText }}
{{ .App.UsageText }}
{{ else }}
{{ .App.Name }} [GLOBAL OPTIONS] command [COMMAND OPTIONS] [ARGUMENTS...]
{{ end }}` + "```" + `
{{ if .GlobalArgs }}
# GLOBAL OPTIONS
{{ range $v := .GlobalArgs }}
{{ $v }}{{ end }}
{{ end }}{{ if .Commands }}
# COMMANDS
{{ range $v := .Commands }}
{{ $v }}{{ end }}{{ end }}`
var FishCompletionTemplate = `# {{ .App.Name }} fish shell completion
function __fish_{{ .App.Name }}_no_subcommand --description 'Test if there has been any subcommand yet'
for i in (commandline -opc)
if contains -- $i{{ range $v := .AllCommands }} {{ $v }}{{ end }}
return 1
end
end
return 0
end
{{ range $v := .Completions }}{{ $v }}
{{ end }}`