-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CLI: discoverability and consistency #2542
Changes from all commits
4d38ee5
e124292
d1a296e
e5df829
d25f640
dd2679d
b4f8f4e
e26625a
8215e33
aebe3b5
ef64a0c
c43db2d
5e4eacb
7756618
1a268b0
23dca67
726bebd
2b201bc
233989b
20b3e98
eb9de5f
124c51d
60f1fc1
2a41d45
bd70017
be15ed8
4aa5733
479ef39
cdb8625
cb029a0
73d1d96
17509ec
0b861e4
af79a84
bd08815
20eb0c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,7 +132,7 @@ func main() { | |
if invoc.cmd != nil { | ||
// we need a newline space. | ||
fmt.Fprintf(os.Stderr, "\n") | ||
printMetaHelp(os.Stderr) | ||
printHelp(false, os.Stderr) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's the diff here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I highly recommend building the branch and playing with the changes live! |
||
} | ||
os.Exit(1) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ const ( | |
|
||
whitespace = "\r\n\t " | ||
|
||
indentStr = " " | ||
indentStr = " " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to be more of enforcing a personal opinion or habit. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No -- this falls under "Terminal formatting / sizing: reduce horizontal indent on help docs". Let's reduce the tool's horizontal footprint so 80 char terminals don't experience weird line wrap. (Fully dynamic smart wrapping would be even cooler, but that's a bit bigger scope than this.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that the commands lib should change the formatting of the helptext at all, otherwise we might try to format things a certain way only to have the code screw things up. A better option I think is to have a commands_test.go file (or similar) that goes through each command and ensures their helptext looks correct (tabs vs spaces, etc) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed that this should be a concern of the library user and not the core commands lib. I can file an issue for that -- it seems like a bigger job than what's in scope for this PR. |
||
) | ||
|
||
type helpFields struct { | ||
|
@@ -74,38 +74,38 @@ func (f *helpFields) IndentAll() { | |
|
||
const usageFormat = "{{if .Usage}}{{.Usage}}{{else}}{{.Path}}{{if .ArgUsage}} {{.ArgUsage}}{{end}} - {{.Tagline}}{{end}}" | ||
|
||
const longHelpFormat = ` | ||
const longHelpFormat = `USAGE | ||
{{.Indent}}{{template "usage" .}} | ||
|
||
{{if .Arguments}}ARGUMENTS: | ||
{{if .Arguments}}ARGUMENTS | ||
|
||
{{.Arguments}} | ||
|
||
{{end}}{{if .Options}}OPTIONS: | ||
{{end}}{{if .Options}}OPTIONS | ||
|
||
{{.Options}} | ||
|
||
{{end}}{{if .Subcommands}}SUBCOMMANDS: | ||
{{end}}{{if .Description}}DESCRIPTION | ||
|
||
{{.Description}} | ||
|
||
{{end}}{{if .Subcommands}}SUBCOMMANDS | ||
{{.Subcommands}} | ||
|
||
{{.Indent}}Use '{{.Path}} <subcmd> --help' for more information about each command. | ||
|
||
{{end}}{{if .Description}}DESCRIPTION: | ||
|
||
{{.Description}} | ||
|
||
{{end}} | ||
` | ||
const shortHelpFormat = `USAGE: | ||
|
||
const shortHelpFormat = `USAGE | ||
{{.Indent}}{{template "usage" .}} | ||
{{if .Synopsis}} | ||
{{.Synopsis}} | ||
{{end}}{{if .Description}} | ||
{{.Description}} | ||
{{end}} | ||
{{if .MoreHelp}}Use '{{.Path}} --help' for more information about this command. | ||
{{end}}{{if .Subcommands}} | ||
SUBCOMMANDS | ||
{{.Subcommands}} | ||
{{end}}{{if .MoreHelp}} | ||
Use '{{.Path}} --help' for more information about this command. | ||
{{end}} | ||
` | ||
|
||
|
@@ -119,7 +119,7 @@ func init() { | |
shortHelpTemplate = template.Must(usageTemplate.New("shortHelp").Parse(shortHelpFormat)) | ||
} | ||
|
||
// LongHelp returns a formatted CLI helptext string, generated for the given command | ||
// LongHelp writes a formatted CLI helptext string to a Writer for the given command | ||
func LongHelp(rootName string, root *cmds.Command, path []string, out io.Writer) error { | ||
cmd, err := root.Get(path) | ||
if err != nil { | ||
|
@@ -169,7 +169,7 @@ func LongHelp(rootName string, root *cmds.Command, path []string, out io.Writer) | |
return longHelpTemplate.Execute(out, fields) | ||
} | ||
|
||
// ShortHelp returns a formatted CLI helptext string, generated for the given command | ||
// ShortHelp writes a formatted CLI helptext string to a Writer for the given command | ||
func ShortHelp(rootName string, root *cmds.Command, path []string, out io.Writer) error { | ||
cmd, err := root.Get(path) | ||
if err != nil { | ||
|
@@ -193,10 +193,16 @@ func ShortHelp(rootName string, root *cmds.Command, path []string, out io.Writer | |
Tagline: cmd.Helptext.Tagline, | ||
Synopsis: cmd.Helptext.Synopsis, | ||
Description: cmd.Helptext.ShortDescription, | ||
Subcommands: cmd.Helptext.Subcommands, | ||
Usage: cmd.Helptext.Usage, | ||
MoreHelp: (cmd != root), | ||
} | ||
|
||
// autogen fields that are empty | ||
if len(fields.Subcommands) == 0 { | ||
fields.Subcommands = strings.Join(subcommandText(cmd, rootName, path), "\n") | ||
} | ||
|
||
// trim the extra newlines (see TrimNewlines doc) | ||
fields.TrimNewlines() | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IPFS
Guidelines provided by @RichardLitt https://github.com/ipfs/community/blob/master/docs-styleguide.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where?
ipfs uses a repository...
? I think this use is IPFS as a command line tool, which is referred to asipfs
notIPFS
. (This must be true here, since IPFS does not use a repository in the local file system -- it's abstracted away at the highest level.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, you are right :) I read it as 'IPFS, the system', not the cli