Closed mxcl closed 1 year ago
We're discussing a solution to that over in #23 .
The idea is to have some environment variables that are required to be set for it to work, similar to make
.
well I was talking about xc foo bar
where bar
is an arg that the xc task can use. Env vars are no use to me in my usecase.
I see, I think this could be a valuable feature. In the case of a task with multiple lines, what would you expect the behaviour to be?
Would you expect it to work as shell scripts do?
# Task
## foo
echo "The Foo Task" echo $1
So in general I have struggled here. The markdown is meant to be human readable, and here we are making it specific for a tool like xc
. But it seems the right approach. We used $@
in exe/md where this means “all args” to most shells.
# Task
## foo
Use `xc foo [arg...]` to run this task.
```sh
echo "The Foo Task"
echo "$@"
```\
Where xc
supports $@
and $1
etc.
Okay I can see that working. But I also agree that as a form of documentation it could get confusing.
In xc
there's a concept of "attributes" that can modify a task in some way like working directory: https://xcfile.dev/task-syntax/directory/
One option could be to create a new Attribute where you can define inputs to a task:
# Task
## foo
Use `xc foo [bar] [baz]` to run this task.
Directory: ./some_dir
Inputs: BAR, BAZ
```sh
echo "The Foo Task"
echo "$BAR"
echo "$BAZ"
Then each input will be converted to an Environment variable.
This way I think it's clearer what is required to run the task? Thoughts?
aah this is a good idea. Nice.
I suppose this could also work nicely with #23 aswell?
# Task
## foo
Use `xc foo [bar] [baz]` to run this task.
Inputs: BAR, BAZ
```sh
echo "The Foo Task"
echo "$BAR"
echo "$BAZ"
Could be run with:
xc foo dog cat
or
BAR=dog BAZ=cat xc foo
I like it. Elegant.
Well I need $@
, eg. I’m trying to add this to @teaxyz/brewkit:
# Tasks
## docker
```sh
export TEA_PREFIX="$SRCROOT"/docker/tea
docker run \
--name tea \
--rm \
--volume "$SRCROOT"/docker/home:/root \
--volume "$SRCROOT"/docker/opt:/root/.tea \
--volume "$SRCROOT":/src \
--env GITHUB_TOKEN=$(gh auth token) \
--env TEA_PANTRY_PATH=/src \
ghcr.io/teaxyz/infuser \
tea +tea.xyz/brewkit "$@"
``\`
The number of args is variable.
I want to put the command in the README so people can see how they could do this manually and that the methods we are using compose other commands. For me that's the power of xc
that you show the user how they could do it themselves.
Anyway, if you don’t feel it fits it's fine as I can just make the command separate. LMK
I do think this fits actually, let me implement this and play around with it a bit too.
I may combine it with the above proposition of an Inputs
attribute.
You can either defined Inputs for a task, or you can use the variadic notation to capture all args.
I'm also working on a new build which uses temporary script files rather than running the tasks line by line. This should make running commands like your docker task easier.
Need to document how this new feature works but the long/short of it is that with this feature, xc now supports $@
and numbered args like $1
within tasks.
As well as named Inputs that can be provided via args or via environment variables.
Specifically I tested it out with your docker
example @mxcl and it works as expected.
Released in https://github.com/joerdav/xc/tree/v0.0.154
Terrific! Thanks,
When we were doing exe/md we supported passing args.
I wouldn’t say it was a homerun, it had caveats we hadn't resolved.
Anyway, thoughts?