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

Replacing Command Line Args Module #125

Open
Tracked by #21
mlucool opened this issue Feb 16, 2016 · 8 comments
Open
Tracked by #21

Replacing Command Line Args Module #125

mlucool opened this issue Feb 16, 2016 · 8 comments

Comments

@mlucool
Copy link

mlucool commented Feb 16, 2016

In order to replace usage of something like https://www.npmjs.com/package/command-line-args it would be helpful to allow arg to have an alias. For example, I want -h and --help to both allow for help to be called.

Example usage:

        help: {
            arg: ['help', 'h'],
            type: Boolean,
            doc: 'Display this usage message',
            default: false
        },

On a related note, getSchemaString seems to print something like:

{
  "properties": {
    "help": {},
    "env": {},
  }
}

Any idea why it is mostly blank. Ideally, I'd like to see the output mirror https://www.npmjs.com/package/command-line-args#module_command-line-args--CommandLineArgs+getUsage

@fgeorgsson
Copy link

Some way of auto-generating CLI help from the schema would be nice. If the user runs
node index.js --help I want to see help output similar to the way commander does it.

None of the available methods .toString, getSchema or getProperties even lists the arg keys. Hard to generate help from that? Ideas?

@madarche
Copy link
Collaborator

@mlucool I'm not against adding support for command-line aliases, though I don't think it's that valuable because command-line args are already supported as long options. I fear it will make the code a bit more complex (and some parts are already too complex for easy maintenance I think). So I would rather avoid it, but it's not a definitive "No". What do other interested parties say?

On the other hand I find @PCguru's idea of auto-generating-CLI-help far more easy to accept. This would not complicate the code, this would only add a new simple method. There is no code at the moment that returns the arg keys, but that should be very easy to develop. This is a nice idea for a PR for a wannabee contributor :-)

Thanks to both of you for your ideas!

@sykaeh
Copy link

sykaeh commented Apr 6, 2016

I would really appreciate both command-line aliases and an auto-generated help message. As far as I can tell, convict currently uses optmist to parse the command line arguments. However optimist has been deprecated since February 2014. So maybe replacing optimist with something like commander would be a good idea anyways.

@mojavelinux
Copy link
Contributor

The lack of short arguments is a pronounced deficiency. It's much more common to use short arguments (single hyphen) than to use the long form. convict is going way against the grain (esp in the Unix world) by only having support for long arguments.

@madarche
Copy link
Collaborator

madarche commented Sep 28, 2017

I'm not opposed to the idea of supporting short arguments. And now, with all the wonderful work of @elyscape and especially the 100% code coverage, we can serenely consider adding new features.

As for the syntax, I would be more in favor of something like:

help: {
            short: 'h',
            type: Boolean,
            doc: 'Display this usage message',
            default: false
        },

Ideas, discussions welcome!

@bodo22
Copy link

bodo22 commented Apr 8, 2019

How is the status on this issue?

Would a PR with the new key short or shortArg like @madarche suggested have a chance of being merged? :)

@A-312
Copy link
Contributor

A-312 commented Dec 7, 2019

With customGetter #313 you will be able to replace 'env' getter by your own getter/function.

@A-312
Copy link
Contributor

A-312 commented Jan 6, 2020

You will be able to do that with :

const useArgOnlyOnce = false;

convict.addGetter('arg', function(value, schema, stopPropagation) {
  const argv = parseArgs(this.getArgs(), {
    configuration: {
      'dot-notation': false
    }
  });
  return schema._cvtCoerce(argv[value]);
}, useArgOnlyOnce, true);

;)

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

7 participants