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

new option type "file" #1188

Open
alexkli opened this issue Jul 25, 2018 · 2 comments
Open

new option type "file" #1188

alexkli opened this issue Jul 25, 2018 · 2 comments

Comments

@alexkli
Copy link

alexkli commented Jul 25, 2018

Many CLI options are meant to be paths to files. Instead of having to use string as type today, and doing the basic file handling in your app, it would be nice to have a dedicated file type for options in yargs.

If an option is of type file yargs would:

  • check if the file exists and if not throw an error with a standard message
  • run it through path.resolve() and return that as option value to the app
  • make bash autocompletion support expect a file here so that -f <TAB> will present available files

This new option would mean these API additions:

  • file(key)
  • option[s](key, opt) would take a new opt.file boolean, as well as support 'file' as value for opt.type
@honzajavorek
Copy link
Contributor

FWIW, in Python's click there are two types to handle this: file and path

@alexkli
Copy link
Author

alexkli commented Aug 11, 2018

BTW, for now I am using coerce to resolve a path argument like in this example:

yargs.positional('file', {
    type: 'string',
    describe: 'Path to input file',
    coerce: f => path.resolve(f)
})

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

No branches or pull requests

2 participants