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

Feature: Addons add commands to the CLI #1196

Merged
merged 12 commits into from
Jun 30, 2014

Conversation

jakecraige
Copy link
Member

You can now have your addon implement a includedCommands hook which returns an object that will be merged with ember-cli's default commands and passed into the Command.extend method for you.

@@ -16,6 +17,11 @@ module.exports = Command.extend({
// Display usage for all commands.
this.ui.write('Available commands in ember-cli:\n');

if(this.project.initializeAddons && this.project.addonCommands) {
Copy link
Member

Choose a reason for hiding this comment

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

When would either of these be false?

Copy link
Member Author

Choose a reason for hiding this comment

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

tests.. How would you recommend resolving this? I've considered created a simple project object fixture to use throughout the tests rather than it being defined all over the place manually

Copy link
Member

Choose a reason for hiding this comment

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

I thought we used https://github.com/stefanpenner/ember-cli/blob/master/tests/helpers/mock-project.js throughout. Are there cases where adding it there wouldn't work?

Copy link
Member Author

Choose a reason for hiding this comment

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

specifically cli-test and help-test both have it manually defined in a few places. That's what I was thinking though, I thought I saw that somewhere.

I can go through and update everything to use that though and remove this check if you want

Copy link
Member

Choose a reason for hiding this comment

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

OK, gotcha. This is OK with me then. I would generally like to fix those other tests so we can avoid this check, but that is probably the subject for another PR.

@jakecraige
Copy link
Member Author

Working on fixing the tests real quick


// Attempt to find command in ember-cli core commands
var command = findCommand(commands, commandName);
if(command) {
Copy link
Contributor

Choose a reason for hiding this comment

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

whitespace between if (

@stefanpenner
Copy link
Contributor

we should consider:

  1. error if it overrides a core command
  2. namespaced only commands for addons ala cordova:build

this is a great step forward, i am quite excited:)

@jakecraige
Copy link
Member Author

@stefanpenner Currently it isn't letting you override a core command in execution, though it will be listed twice in the help. I can make it throw an error instead though if you'd prefer

For number 2, you can namespace it if you want right now, it's just not required. If we want to make it required I can do that as well. Are you just thinking we should to distinguish addon commands vs core?

@stefanpenner
Copy link
Contributor

@jakecraige rather then throwing, lets print out and error..

as for name spacing, I am also curious about this. If we force namspacing, it will prevent collisions but be more verbose. Thoughts?

@rwjblue
Copy link
Member

rwjblue commented Jun 29, 2014

I would personally prefer to go without namespacing initially. We can always revisit if we see folks abusing the system, but if we require namespacing that inherently means that commands become quite a bit longer to type out.

@jakecraige
Copy link
Member Author

@stefanpenner I don't see much of a benefit right now since I've now got it logging a warning to annoy you if you do override it and it won't actually let you anyways. If it becomes an issue we could easily swap it to print out an error instead

@stefanpenner
Copy link
Contributor

@jakecraige sound ok

@jakecraige
Copy link
Member Author

@stefanpenner and @rjackson This seems good now. Let me know if there's anything else we need for it


addonPkg['ember-addon'] = addonPkg['ember-addon'] || {};
if(fs.existsSync(pkgPath)) {
Copy link
Member

Choose a reason for hiding this comment

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

Why add this guard?

Copy link
Member Author

Choose a reason for hiding this comment

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

The generator tests freak out without it, it tries to require the file and npm install hasn't been ran so it throws an error

Copy link
Member

Choose a reason for hiding this comment

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

I see, seems OK then.

@rwjblue
Copy link
Member

rwjblue commented Jun 30, 2014

Will need a rebase (likely due to the changelog changing).

@jakecraige
Copy link
Member Author

@rjackson done

@stefanpenner
Copy link
Contributor

rebase is needed again (Sorry)

@jakecraige
Copy link
Member Author

@stefanpenner done

@stefanpenner
Copy link
Contributor

LGTM

@rwjblue
Copy link
Member

rwjblue commented Jun 30, 2014

👍

stefanpenner added a commit that referenced this pull request Jun 30, 2014
Feature: Addons add commands to the CLI
@stefanpenner stefanpenner merged commit a957341 into ember-cli:master Jun 30, 2014
@visualjeff
Copy link

You guys are awesome!!!

@jakecraige jakecraige deleted the feature/addon_commands branch July 9, 2014 22:55
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.

4 participants