Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

variadic style tasks #89

Open
moondev opened this issue Jul 9, 2021 · 2 comments
Open

variadic style tasks #89

moondev opened this issue Jul 9, 2021 · 2 comments

Comments

@moondev
Copy link

moondev commented Jul 9, 2021

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/[email protected] -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/[email protected] -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
Copy link

smyrman commented Jul 9, 2021

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
Copy link
Author

moondev commented Jul 9, 2021

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

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

No branches or pull requests

2 participants