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

Help weirdness #364

Closed
nwinkler opened this issue Oct 1, 2013 · 3 comments
Closed

Help weirdness #364

nwinkler opened this issue Oct 1, 2013 · 3 comments

Comments

@nwinkler
Copy link
Contributor

nwinkler commented Oct 1, 2013

I've noticed a couple of weird things with the --help option:

  • When using the --help option for a generator, the help message always shows the help for the init command. Example: yo generator --help shows yeoman init [options], whereas I would expect something like yo generator [options].
  • Using the --help option for a sub-generator that expects a name parameter (extending NamedBase) always throws an error due to the missing required parameter. Example: yo generator:subgenerator --help gives the following error:
events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: Did not provide required argument name!
    at SubGeneratorGenerator.argument (/usr/local/lib/node_modules/generator-generator/node_modules/yeoman-generator/lib/base.js:211:31)
    at SubGeneratorGenerator.NamedBase (/usr/local/lib/node_modules/generator-generator/node_modules/yeoman-generator/lib/named-base.js:16:8)
    at new SubGeneratorGenerator (/usr/local/lib/node_modules/generator-generator/subgenerator/index.js:6:31)
    at Environment.create (/usr/local/lib/node_modules/yo/node_modules/yeoman-generator/lib/env.js:366:10)
    at Environment.run (/usr/local/lib/node_modules/yo/node_modules/yeoman-generator/lib/env.js:409:24)
    at init (/usr/local/lib/node_modules/yo/bin/yo:98:7)
    at pre (/usr/local/lib/node_modules/yo/bin/yo:110:3)
    at Object.<anonymous> (/usr/local/lib/node_modules/yo/bin/yo:135:1)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)

This is rather unexpected. When using the --help option, I shouldn't need to know that I need to provide a required argument. yo generator:subgenerator --help foo works fine, but I find it rather unnecessary that I need to provide the dummy foo argument just to find out the expected arguments and options. Usability would be a lot better if I wouldn't have to know about required parameters if I'm just calling help.

Does that make sense?

@nwinkler
Copy link
Contributor Author

nwinkler commented Oct 1, 2013

OK, the first item seems to be fixed by this recent commit: 4c21283

I'm using version 0.13.4, which doesn't include this commit - so that explains that.

@nwinkler
Copy link
Contributor Author

nwinkler commented Oct 1, 2013

The issue with the required attribute and help seems to be a bit of a chicken/egg issue. The problems is caused by the fact that the Base.prototype.argument function both defines the expected argument and also immediately checks for its presence if the argument is defined as required.

If we add a check for the help option before defining the required parameters, we can print the help message, but it won't include the required parameters, since they haven't been defined yet.

The clean way to fix this would be to split up the definition of the parameters and then check for the required parameters later:

  1. Define the parameters, but don't check for presence of required parameters
  2. Check for the presence of the help option. If it's set, print the help message including the definition of the required parameters and then exit.
  3. As a last step, check for required parameters. If there are multiple required parameters missing, print a message listing all of the missing required parameters.

@SBoudrias
Copy link
Member

Hi, this have been fixed in this commit: 4c21283

It should be published with the next yeoman-generator release. Stay tune.

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