yeoman / yo

CLI tool for running Yeoman generators
http://yeoman.io
BSD 2-Clause "Simplified" License
3.85k stars 399 forks source link

option alias not working? #319

Closed JamesMessinger closed 8 years ago

JamesMessinger commented 9 years ago

I have an option with an alias, like this:

module.exports = generators.Base.extend({
    constructor: function() {
        generators.Base.apply(this, arguments);
        this.option('opt', {alias: 'o', desc: 'testing aliases'});
    }
});

When I run yo mygenerator --help, I see the following output:

Usage:
  yo mygenerator:app [options] 

Options:
  -h,   --help        # Print the generator's options and usage
        --skip-cache  # Do not remember prompt answers
  -o,   --opt         # testing aliases

If I run my generator with yo mygenerator --opt, it works fine. generator.options.opt is true, as expected. But if I run my generator with yo mygenerator -o, it doesn't work. generator.options.opt is undefined. It seems like option aliases aren't working.

The same applies for the --help option. Running yo --help works fine, but yo -h doesn't work.

SBoudrias commented 9 years ago

ping @sindresorhus might this be another regression due to switching from nopt to meow?

sindresorhus commented 9 years ago
yo electron -o

Passes the following to env.run(args, opts);:

['electron']
{
  o: true
}

While with nopt it passed:

['electron']
{
  o: true,
  argv: {
    remain: ['electron'],
    cooked: ['electron', '-o'],
    original: ['electron', '-o']
  }
}

The .run() documentation is a bit limited, so not sure if this ever worked or should have. ?

http://yeoman.github.io/generator/Environment#run

sindresorhus commented 9 years ago

Running yo --help works fine, but yo -h doesn't work.

That's intentional.

SBoudrias commented 9 years ago

Alright then, classifying as a bug. Feel free to dig the code if you want this resolved faster.

JamesMessinger commented 9 years ago

@sindresorhus - If it's intentional that yo -h doesn't work, then why is it listed as an option when in yo --help:

~: yo --help
Usage: yo GENERATOR [args] [options]

General options:
  -h, --help     # Print generator's options and usage
  -f, --force    # Overwrite files that already exist
sindresorhus commented 9 years ago

I guess that help text needs to be updated.

kevva commented 9 years ago

https://github.com/yeoman/yo/blob/master/lib/usage.txt. As you can see it's already updated. @BigstickCarpet, could you try updating yo?

JamesMessinger commented 9 years ago

Latest version is 1.4.6, right? It still shows the old usage text

kevva commented 9 years ago

Hm, yeah. We haven't pushed out a new release since that changed.

eddiemonge commented 9 years ago

It was updated https://github.com/yeoman/yo/commit/5905f6225e8ac1644dbcf58c5d45f16cc9f3c251 What is interactive help?

SBoudrias commented 9 years ago

Hey, just checked into that issue. This is effectively a bug and it's not just about fixing the text. Aliases don't work anymore. When calling this.option() in a generator, there's always been a choice to add a shortname alias.

This feature should work as before. We'll need to investigate.

Nitro-N commented 8 years ago

My yo version is 1.7.0, but I have same problem. Aliases works same as name. If I have option "bundle" with alias "b" and run generator with arument "-b foo", then my options object will be {bundle: undefined, b:'foo'} npm -v 3.8.3

SBoudrias commented 8 years ago

@Nitro-N the yo version doesn't matter. It's about the yeoman-generator version.

Nitro-N commented 8 years ago

@SBoudrias Yep! My mistake, sorry.