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

Autogenerate flag help when no helpMessage is given #80

Open
matthewadams opened this issue Mar 15, 2018 · 5 comments
Open

Autogenerate flag help when no helpMessage is given #80

matthewadams opened this issue Mar 15, 2018 · 5 comments

Comments

@matthewadams
Copy link

I'm coming from commander, which autogenerates documentation on flags, and was surprised to see that meow's autoHelp feature doesn't do the same.

// in index.js
const cli = require('meow')({
  flags: {
    'initial-indent': {
      type: 'string',
      alias: 'n',
      description: 'Initial indentation level'
      default: '0'
    },
    indent: {
      type: 'string',
      alias: 'i',
      description: 'YAML indentation level'
      default: '2'
    }
  }
})
cli.showHelp()

should generate output something like

$ ./index.js

  My cool tool description

  Options:
    -n, --initial-indent  [value]  Initial indentation spaces.  Optional; default 0.
    -i, --indent          [value]  YAML indentation spaces.  Optional; default 2.
@sindresorhus
Copy link
Owner

Meow was initially just created to be a small helper lib for making tiny CLI's. It has now outgrown that, but it never had ambitions of being a Commander replacement.

I wouldn't mind having this though.

matthewadams added a commit to matthewadams/meow that referenced this issue Mar 16, 2018
matthewadams added a commit to matthewadams/meow that referenced this issue Mar 16, 2018
@lukasoppermann

This comment has been minimized.

@sindresorhus
Copy link
Owner

#82 was closed as I got no response. If anyone wants to work on this, you can probably continue where that PR left off. Make sure to address the feedback given there.

@ybiquitous
Copy link
Contributor

I've created a new PR #140!

@verheyenkoen
Copy link

verheyenkoen commented Apr 8, 2022

I'd love this as well. If not possible to completely auto-generate, maybe consider the option to have a helpMessage object instead of a string, like so:

const cli = meow({
    description: 'A tool that does stuff with files and encodings',
    inputs: ['<file>', '<encoding>'], // command name is auto-prepended based on process.argv
    options: { // alternatively add the flag description to the flags object and make this property a boolean switch
        '-c': 'Convert file encoding', // long option name auto-added based on flags object
        '--dry-run': 'Output commands instead of executing', // option alias auto-added if available
        '--help': 'Show this help message',
    },
    examples: {
        'input.txt utf-8': 'Loads this file and converts to UTF-8', // command name is auto-prepended based on process.argv
        '—dry-run other_file.csv': 'Outputs the file to stdout',
   }
},
{
    importMeta: import.meta,
    flags: {}
})

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

Successfully merging a pull request may close this issue.

5 participants