sindresorhus / meow

🐈 CLI app helper
MIT License
3.53k stars 150 forks source link

Allow single line help messages #229

Closed tommy-mitchell closed 1 year ago

tommy-mitchell commented 1 year ago

Currently, help messages always have surrounding newlines:

https://github.com/sindresorhus/meow/blob/dc0e33cc33c890bbd8dd9c74d5e0db7173335fbb/index.js#L210

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 commented 1 year ago

Related: #95

sindresorhus commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

tommy-mitchell commented 1 year ago

I'd be okay with that.

sindresorhus commented 1 year ago

Ok. Let's do that.

tommy-mitchell commented 1 year ago

Should this extend to description as well? Cases:


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

$ my-command --version
0.5.2

$ 
sindresorhus commented 1 year ago

Should this extend to description as well? Cases:

Yes

sindresorhus commented 1 year ago

@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 commented 12 months ago

@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 commented 12 months ago

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.

https://github.com/sindresorhus/meow/issues/240#issuecomment-1698605364