Skip to content

Add an option sieve for all commands#15

Merged
gigabo merged 7 commits intoasini:masterfrom
gigabo:option-sieve
Sep 21, 2016
Merged

Add an option sieve for all commands#15
gigabo merged 7 commits intoasini:masterfrom
gigabo:option-sieve

Conversation

@gigabo
Copy link
Copy Markdown
Contributor

@gigabo gigabo commented Sep 20, 2016

Allow config:

  • At the top level of asini.json
  • In commands.<command> in asini.json
  • On the command-line

Each of those supercedes previous values.

Example:

{
  "asini": "x.x.x",
  "version": "1.2.0",
  "ignore": "unrelated-package",
  "commands": {
    "publish": {
      "ignore": "test-package"
    }
  }
}

This deprecates:

  • bootstrapConfig.ignore
  • publishConfig.ignore

These still work, with the lowest precedence. Their use triggers a warning.

This addresses some of the TODOs and feedback from #8.

Allow config:

- At the top level of `asini.json`
- In `commands.<command>` in `asini.json`
- On the command-line

Each of those supercedes previous values.

Example:

```json
{
  "asini": "x.x.x",
  "version": "1.2.0",
  "ignore": "unrelated-package",
  "commands": {
    "publish": {
      "ignore": "test-package"
    }
  }
}
```

This deprecates:

- `bootstrapConfig.ignore`
- `publishConfig.ignore`

These still work, with the _lowest_ precedence.  Their use triggers a warning.
@gigabo
Copy link
Copy Markdown
Contributor Author

gigabo commented Sep 20, 2016

Ugh... no Object.assign in node 0.10 or 0.12...

Maybe we can just drop those?

Since we're not required to support everything that babel supports now? 👹

@gigabo gigabo mentioned this pull request Sep 20, 2016
Comment thread src/Command.js
}

get className() {
return this.constructor.name;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

not a big fan of this, but i guess it works. ¯_(ツ)_/¯

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You would prefer each command implement a name getter?

Like:

class LsCommand extends Command {
  ...
  get name() { return "ls" }
}

That's more explicit and flexible... but it's a lot of boilerplate, too.

Copy link
Copy Markdown
Contributor

@rygine rygine Sep 20, 2016

Choose a reason for hiding this comment

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

something like that. yes, a bit more boilerplate, but would support classenames without Command in them and additional characters. not sure there's an advantage there, just a thought.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

and in the future, when asini is an asini repo, custom commands should be possible, and names could potentially clash. it might be nice to be explicit with the name rather than relying on the class name.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I see your point. Feels a little bit magic to base it on the class name.

My thought is that it's easier to get class *Command right than it is to set up a name getter. It also doesn't seem very onerous to require a naming convention for command classes. They will be relatively few, and they operate in the context of a framework.

How about I add a check for the Command suffix on class names and throw an error if a class fails to implement correctly?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oops, your second comment didn't show up when I was typing my response.

Clashing names would be a problem no matter which way they're specified.

How about errors on:

  • Invalid class name
  • Name collision

That will make it easier to catch problems in the future.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Okay, I've got this queued up for a follow-up PR, since it works well as a standalone.

Also added an error on:

  • A class that doesn't extend Command

Will submit after this lands.

Comment thread src/Command.js Outdated

_legacyOptions() {
let opts = {};
if (this.name === "bootstrap" && (this.repository.asiniJson || {}).bootstrapConfig) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i think this could be part of repository.asiniJson, always ensuring an object is returned.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I wavered on that. Wasn't sure if there would ever be a case where we cared whether it was even defined. I guess probably not. I'll clean this up.

Comment thread src/Command.js
}
return opts;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what about something like this?

["bootstrap", "publish"].forEach((command) => {
  if (this.name === command && this.repository.asiniJson[`${command}Config`]) {
    logger.warn(`\`${command}Config.ignore\` is deprecated.  Use \`commands.${command}.ignore\`.`);
    opts.ignore = this.repository.asiniJson.[`${command}Config`].ignore;
  }
});

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

🤘

Comment thread src/Command.js

// CLI flags always override everything.
this.flags,
);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i think the Flags section of the README need an entire section talking about precedence.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh, yeah... good call!

@gigabo
Copy link
Copy Markdown
Contributor Author

gigabo commented Sep 21, 2016

Alright, unless there are any objections I'm going to merge this in a few and get the follow up command validation PR up for review.

Copy link
Copy Markdown
Contributor

@rygine rygine left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants