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

Enable ember generate <blueprint> --help for individual blueprint docs #3316

Merged
merged 1 commit into from
Feb 20, 2015

Conversation

trabus
Copy link
Contributor

@trabus trabus commented Feb 19, 2015

This PR fixes #2553, adding the ability to add printDetailedHelp to blueprints.

I've extracted the help logic from lookup-command.js and added a then in the command processing promise chain in cli.js which allows a command to exit before running if the -h or --help option is present. From there the help command is run with the original options passed in (in addition to the command name).

I've added the help option to availableOptions for all commands, which as a side effect lists the --help option as an availableOption for every command. For example:

// with --help added to availableOptions
ember version <options...>
  outputs ember-cli version
  aliases: v, version, -v, --version
  --verbose (Boolean) (Default: false)
  --help (Boolean) (Default: false)
    aliases: -h

// without
ember version <options...>
  outputs ember-cli version
  aliases: v, version, -v, --version
  --verbose (Boolean) (Default: false)

I can remove this if desired, which would go back to the current setup where the --help option is assumed present.

I still need to write tests for this, and I would like to follow this PR up with adding printDetailedHelp to all of the built-in blueprints that could use it. I've mainly put this up for review as I progress on it.

@trabus trabus changed the title Enable ember generate <blueprint> --help for individual blueprint docs [WIP] Enable ember generate <blueprint> --help for individual blueprint docs Feb 19, 2015
@kimroen
Copy link
Contributor

kimroen commented Feb 19, 2015

Some previous discussion and ideas regarding the blueprint-parts of this: #1279 (comment)

@trabus
Copy link
Contributor Author

trabus commented Feb 19, 2015

I've removed the help option from availableOptions on all commands, as it was breaking tests due to the extra option being printed.

I took an initial crack at the model help text, but it needs some work. Input on this part in particular would be great. I'm thinking that blueprint help should probably have some convenience methods to handle formatting, and that should probably live on the blueprint model somewhere. The current ember g model -h output looks like this:

Requested ember-cli commands:

ember generate <blueprint> <options...>
  Generates new code from blueprints.
  aliases: g
  --dry-run (Boolean) (Default: false)
    aliases: -d
  --verbose (Boolean) (Default: false)
    aliases: -v
  --pod (Boolean) (Default: false)
    aliases: -p

      model <name> <attr:type>
        Generates an ember-data model.
        You may generate models with as many attrs as you would like to pass. The following attribute types are supported:
          <attr-name>
          <attr-name>:array
          <attr-name>:boolean
          <attr-name>:date
          <attr-name>:object
          <attr-name>:number
          <attr-name>:string
          <attr-name>:belongs-to:<model-name>
          <attr-name>:has-many:<model-name>

        For instance: `ember generate model taco filling:belongs-to:protein toppings:has-many:toppings name:string price:number misc`
        would result in the following model:

        import DS from 'ember-data';
        export default DS.Model.extend({
          filling: DS.belongsTo('protein'),
          toppings: DS.hasMany('topping')
          name: DS.attr('string'),
          price: DS.attr('number')
          misc: DS.attr()
        });

@joostdevries
Copy link
Member

@trabus This looks nice. Right now, ember points you to use the help command, wouldn't it make more sense to also use ember help generate model instead of ember generate model --help?

@trabus
Copy link
Contributor Author

trabus commented Feb 20, 2015

Actually ember generate model --help is equivalent to ember help generate model, the --help option exits the command early and turns it into a help command. Both commands work and have the same result.

var commandName = args.shift();
var commandArgs = args;
return Promise.hash(environment)
.then(function(environment) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It becomes harder to review the changes because you're changing the syntnax here (moving then to a new line and indenting the block). I'd put that kind of stuff in a separate pr.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've reverted the formatting for now.

@trabus trabus changed the title [WIP] Enable ember generate <blueprint> --help for individual blueprint docs Enable ember generate <blueprint> --help for individual blueprint docs Feb 20, 2015
@trabus
Copy link
Contributor Author

trabus commented Feb 20, 2015

I don't know why appveyor is failing, but it's bailing before even running the tests.

@joostdevries
Copy link
Member

I really like the functionality this provides. I'm not sure whether the current JS implementation or a markdown file as suggested in #1279 should be preferred though. I also think we might be able to simplify/clarify the implementation a little bit (to make it more transparent what's happening).
@jgwhite @stefanpenner what do you think?

@trabus
Copy link
Contributor Author

trabus commented Feb 20, 2015

If we can throw a markdown file in a blueprint, then parse that into color text, I'm absolutely for that (it would be much easier and better than string concatenation like we're currently doing). I'm sure something like that is possible, but I'm not familiar with a way to do it myself.

I like how projects like sails have README.md files in folders for some of the files, and they also use them for their docs I've noticed.

@jgwhite
Copy link
Contributor

jgwhite commented Feb 20, 2015

Seems like the markdown part could come later, if desirable. This adds lots of value as it currently stands.

@trabus
Copy link
Contributor Author

trabus commented Feb 20, 2015

Now we just need to go through and add printDetailedHelp to all the blueprints that could use it! ;)

@trabus
Copy link
Contributor Author

trabus commented Feb 20, 2015

Seems like the markdown part could come later, if desirable. This adds lots of value as it currently stands.

I could see the printDetailedHelp become a builtin method for blueprints that would check for a markdown file, then parse it into terminal output.

@jgwhite
Copy link
Contributor

jgwhite commented Feb 20, 2015

I could see the printDetailedHelp become a builtin method for blueprints that would check for a markdown file, then parse it into terminal output.

Totally.

Now we just need to go through and add printDetailedHelp to all the blueprints that could use it! ;)

Do you want to add all the detailed help in this PR, or have it happen piecemeal in PRs that follow?

I’d say LGTM and the open it up to the community to drive detailed documentation of blueprints.

@trabus
Copy link
Contributor Author

trabus commented Feb 20, 2015

Do you want to add all the detailed help in this PR, or have it happen piecemeal in PRs that follow?

I vote piecemeal. Maybe I can get the markdown parsing in sooner than later, and we'd save ourselves from having to write the help docs twice.

@jgwhite
Copy link
Contributor

jgwhite commented Feb 20, 2015

Cool. LGTM.

Looks like the AppVeyor failure is a problem installing Phantom. Can someone with the keys re-run the build?

@johanneswuerbach
Copy link
Contributor

@jgwhite just submitted #3322 to fix AppVeyor

@jgwhite
Copy link
Contributor

jgwhite commented Feb 20, 2015

@johanneswuerbach awesome thank you.

@@ -61,6 +61,9 @@ function Command() {
// Options properties
this.availableOptions = this.availableOptions || [];
this.anonymousOptions = this.anonymousOptions || [];
// push in help option for all commands
// this.availableOptions.push({ name: 'help', type: Boolean, default: false, aliases: ['h'] });

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we delete these lines altogether?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What lines?

Sorry, forgot about those after I commented them out. ;)

@trabus
Copy link
Contributor Author

trabus commented Feb 20, 2015

Rebased and re-ran travis (after a timeout on 0.12). AppVeyor seems okay aside from the timeout, but that's also happening for master.

@rwjblue rwjblue merged commit de0e3a8 into ember-cli:master Feb 20, 2015
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

Successfully merging this pull request may close these issues.

ember generate docs - specifically model generator
6 participants