joerdav / xc

Markdown defined task runner.
https://xcfile.dev/
MIT License
1.17k stars 27 forks source link

Required tasks should inherit inputs (Or be able to map inputs for task X to inputs for required task Y) #103

Open chrisalbright opened 10 months ago

chrisalbright commented 10 months ago

Given:

For example, given a readme:

Tasks

y

Inputs: v

echo my inputs are $v

x

Requires: y

echo 'hello world'

this invocation will work: v=hello xc x

but this one will fail: xc x hello

Likewise, this readme will also fail in the same way as described above:

Tasks

y

Inputs: v

echo my inputs are $v

x

Inputs: v Requires: y

echo "$v world"
joerdav commented 10 months ago

I can see the issue you are raising here. Let's workshop some potential solutions.

I think each task should expresss it's own inputs, so the first example you provided I believe should fail as task y expresses no required inputs.

You should be able to create Requires statements that contain inputs:

Requires: y hello

But this doesn't help if you would like to have the input to y be dynamic.

Maybe if an input is named the same as an input on a required task, it should be mapped?

joerdav commented 10 months ago

What about if requires inputs are expanded:

## y

Inputs: v

echo $v


## x

Inputs: v

Requires: y $v
chrisalbright commented 10 months ago

I think the second idea is better, because it is more explicit and seems easier to understand. I'd thought the first idea would probably be easier to implement, and possibly simpler to use.

bartmeuris commented 8 months ago

I was looking at the issues here, having a similar use-case, where I would like to change the behavior of a dependency/requirement depending on which task it triggers.

The second solution could work, but I was more thinking of inheriting environment variables of parent tasks, but since this could break existing setups, maybe introduce the concept of "global" environment variables, which could both be set directly under the ## Tasks, and overridden per task for itself and the required tasks/dependencies it would trigger.