Skip to content
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

Allow single line help messages #229

Closed
tommy-mitchell opened this issue Mar 21, 2023 · 11 comments · Fixed by #232
Closed

Allow single line help messages #229

tommy-mitchell opened this issue Mar 21, 2023 · 11 comments · Fixed by #232

Comments

@tommy-mitchell
Copy link
Contributor

Currently, help messages always have surrounding newlines:

meow/index.js

Line 210 in dc0e33c

help = (description ? `\n ${description}\n` : '') + (help ? `\n${help}\n` : '\n');

The user should be able to have a single line message (i.e. without a leading newline). This can either be an option or can be inferred if the provided help text has no newlines:

const cli = meow('$ my-command <arg1>', {
  padHelp: false,
});

// or

const cli = meow('$ my-command <arg1>', { /* … */ });
@tommy-mitchell
Copy link
Contributor Author

Related: #95

@sindresorhus
Copy link
Owner

What's the argument? It looks better when surrounded by newlines. The bar for adding options is high. I doubt I would add an option for something as minor as this.

@tommy-mitchell
Copy link
Contributor Author

I agree not an option, though I think it can be a little unintuitive that meow('single line usage info') becomes

$ my-command

	single line usage info


I expected it to be

$ my-command
single line usage info

For example, cp has the following usage info:

$ cp
usage: cp [-R [-H | -L | -P]] [-fi | -n] [-aclpsvXx] source_file target_file
       cp [-R [-H | -L | -P]] [-fi | -n] [-aclpsvXx] source_file ... target_directory

Perhaps if the provided help text has no newlines, it could be outputted without a leading newline.

However, I do understand the argument for readibility with spacing and enforcing best practices on users. Feel free to close this.

@sindresorhus
Copy link
Owner

Maybe we could not indent it if it's a single line? That would make it look slightly nicer.

@tommy-mitchell
Copy link
Contributor Author

I'd be okay with that.

@sindresorhus
Copy link
Owner

Ok. Let's do that.

@tommy-mitchell
Copy link
Contributor Author

Should this extend to description as well? Cases:

  • help and description are set - same behavior as now:

    $ my-command
    
      My command's description.
    
      My command's help.
    
    
  • only help is set - no indent:

    $ my-command
    
    My command's help.
    
    
  • only description is set - no indent:

    $ my-command
    
    My command's description.
    
    

Related, should the fact that --version is single-line have any bearing on this?

$ my-command --version
0.5.2

$ 

@sindresorhus
Copy link
Owner

Should this extend to description as well? Cases:

Yes

@sindresorhus
Copy link
Owner

@tommy-mitchell What do you think of removing the indent in meow? I no longer remember why I added it and it seems like all the major CLI frameworks (swit-arguments-parser, Clap, Yargs, etc.) do not use an indent.

@tommy-mitchell
Copy link
Contributor Author

@sindresorhus I kind of like how it looks, but I think a simple indent option would suffice:

meow(`
	Usage
	  $ foo [--bar]
`, {
	importMeta: import.meta,
	indent: false,
	flags: {
		// ...
	},
});

Where indent is:

/* @default 2 */
indent: number | false

@sindresorhus
Copy link
Owner

I also used to like it, but I'm seeing less value of it now for some reason. We can start with an option. We'll need that anyway if we decide to change the default in the future. Thanks.

#240 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants