rliebz / tusk

The modern task runner
https://rliebz.github.io/tusk/
MIT License
236 stars 21 forks source link

variadic style tasks #89

Open moondev opened 3 years ago

moondev commented 3 years ago

First of all, just want to thank you for tusk! It's been a pleasure to use and is now a main component of my workflow. With upcoming go run support in 1.17.x for import paths it can run bash style via a shebang.

#!/usr/bin/env -S go run github.com/rliebz/tusk@v0.6.2 -f
---
tasks:
  hello:
    run:
      - echo world

My feature request is for "variadic style" tasks, that is, the ability to define a task with an arbitrary number of options and/or arguments, similar to this example: https://gobyexample.com/variadic-functions

My use-case for this is I often define tasks as a wrapper of sorts for another program, such as this example for kind

#!/usr/bin/env -S go run github.com/rliebz/tusk@v0.6.2 -f
---
tasks:
  kind:
    run:
      - go run sigs.k8s.io/kind@latest

./tusk.yaml kind runs kind but in order to pass arguments and options I would need to define them all. For non user-exposed tasks i've been using global options which works well enough

---
options:
  kind:
    default: go run sigs.k8s.io/kind@latest
tasks:
  create:
    options:
      name:
        default: my-cluster
    run:
      - ${kind} delete clusters --all
      - ${kind} create cluster --name ${name}

However it would be handy to be able to expose a command that just passes everything through, this way tasks could be easily defined as a proxy of sorts for a program

---
options:
  kind:
    default: go run sigs.k8s.io/kind@latest
tasks:
  kind:
    options: any
    args: any
    run:
      - ${kind} ${options} ${args}

This could enable easily using a task like it was the original program without needing to define everything

tusk kind delete clusters --all
tusk kind create cluster --name yhatzee
tusk kind get nodes --name yhatzee

Interested in your thoughts on this, thanks again!

smyrman commented 3 years ago

Comment from the sideline.

We also use tusk mostly to wrap other tools. However, from my point of view, this suggestion is problematic, because perhaps one of the most useful feature of tusk over other tools is the explicit declaration of options, including very good auto-completion and the possibility to write usage strings. This ensures that the task file is self-descriptive, needs minimal documentation, and is easy to use for multiple team members.

Allowing a variadic pass-through, espcially when it comes to options is encoring a pattern that favors simple tusk files over usability, which in my own opinion, is removing most of the benefits of using tusk in the first place. If this is how most tasks will look like, you might consider a shell script.

Allowing the last listed argument to be variadic though (similar to Go functions) is probably a nice thought, if not one I have often seen a need for.

moondev commented 3 years ago

Another alternative i've used is passing the args and commands as an string, bash -c style

tasks:
  kind:
    options:
      cmd:
        short: c
    run:
      - go run sigs.k8s.io/kind@latest ${cmd}

this handles tusk kind and tusk kind -c 'create cluster --name my-cluster' but tusk kind create cluster ... would be more intuitive.

Curious if something like kubectl uses with -- is relevant here: kubectl exec -it some-pod -- cat /etc/os-release