google / grinder.dart

Dart workflows, automated
https://pub.dev/packages/grinder
BSD 3-Clause "New" or "Revised" License
261 stars 36 forks source link

How do I access the command-line args in a task? #175

Open sethladd opened 9 years ago

sethladd commented 9 years ago

context doesn't seem to have it.

use case: I want to run something like grind bumpversion minor or grind bumpversion plus and automate the steps to bump a version

seaneagan commented 9 years ago

The top-level grinderArgs() is intended to expose those, but I'm pretty sure if you pass in any positional args, options, or flags that grinder doesn't understand, grinder's arg parsing will currently fail anyways. The issue for fixing that is #116.

devoncarew commented 9 years ago

Do we need to support something like this:

grind foo_task some args bar_task other args

? Or do we just pass all args to the last task mentioned? Or only allow one task to be listed on the command-line if any task args are used?

grind foo_task i get all the --args
sethladd commented 9 years ago

I think this would be confusing, as one task's args could be the name of a task: grind foo_task some args bar_task other args

sethladd commented 9 years ago

What do other systems do?

seaneagan commented 9 years ago

I think all positional args should be task names, so task args must be --option[=]value or --flag. I think we can allow those options/flags anywhere on the line. #116 discusses a mechanism to declare and be injected with args they care about (similar to unscripted), interested to get feedback on that.

Grunt allows targets:

grunt deploy:prod

I don't think I like that as much, but it is a way to send args to a single task instead of all who use the same named options.

seaneagan commented 9 years ago

One thing to note is that you may want to pass an option to a dependency task, which is not even specified on the command line. --option=value and --flag would be the ticket for that.

sethladd commented 9 years ago

target might work for me.

Ultimate I want to do this:

grind version:bump:major

grind version:bump:minor

etc

So I can create a deployment workflow:

devoncarew commented 9 years ago

Let's plan on releasing 0.7.0 w/o being gated on this, but following up in an 0.7.1 to address letting tasks have args.

sethladd commented 9 years ago

sgtm.

sethladd commented 9 years ago

Now that 0.7.0 is out, I'd like to re-open. My use case is, I had a single task that wanted to take an argument. The workaround was to create two differently named tasks. In the old syntax:

taskBumpMajor() { bump(major); }

taskBumpMinor() { bump(minor); }

But of course, I can't deal with more than one arg to a task, unless I want an explosion of task names :)

So, I'd like to be able to call a task and somehow pass it args for more specialized behavior, from the command line.

Thanks!

zoechi commented 9 years ago

Maybe this could help here too dart-lang/args#9

devoncarew commented 9 years ago

Just anecdotally, I ran into this use case myself this morning. I wanted to pass a single text param to a task: a new milestone version that would be re-written in a few places in the source.