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

garn.shell argparsing helper #439

Open
jkarni opened this issue Nov 24, 2023 · 0 comments
Open

garn.shell argparsing helper #439

jkarni opened this issue Nov 24, 2023 · 0 comments

Comments

@jkarni
Copy link
Contributor

jkarni commented Nov 24, 2023

I was thinking a bit more about garn.shell, and how it ideally should be a great script-writing helper like just. It is unfortunate that:

  1. Shell completion breaks for arguments to the underlying executable
  2. The help for the underlying executable is poorly integrated into the garn help
  3. It's harder to deal with arguments than it is in, say, a just recipe
  4. (Arguably,) it'd be nice to not need --.

And it occurred to me we can solve all 3 (or 4 if we wish) by allowing the run command to be a function, and then have a little description/validator for it (a lot like yargs. E.g.:

// These just do overloading to figure out how many arguments are necessary. Useful for one-off, simple scripts
garn.shell("my command", ([arg1, arg2]) => `echo "Got arguments ${arg1} and ${arg}`")

// This, with the third argument, is more "production-grade". We do more validation, and can have more informative help and completion
garn.shell("my command", (args) => `echo "Running on port ${args.port}`"), {
  args:  {
    port: {
      kind: "positional"
      type: "integer"
      default: 8000
      description: "The output port"
    }
    ...
  }
}

How would this work? Well, the idea is that args would become not the eventual value passed, but a (list of/record of/individual) shell variable (e.g. $GARN_ARG_PORT) that gets interpolated statically in the shell script. Then, we wrap the shell script in something that does shell processing and sets those variables accordingly.

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

No branches or pull requests

1 participant