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

feat: export ENV vars command line clap2env tool #52

Open
dzmitry-lahoda opened this issue Jan 4, 2024 · 4 comments
Open

feat: export ENV vars command line clap2env tool #52

dzmitry-lahoda opened this issue Jan 4, 2024 · 4 comments

Comments

@dzmitry-lahoda
Copy link

dzmitry-lahoda commented Jan 4, 2024

flow considered

  1. use config of CLI defined in TOML/YAML file
  2. parse command line parameters
  3. export CONSTANT_CASE ENV vars.
  4. so any script/app running after can access to ENV vars parsed

https://discourse.nixos.org/t/nix-bash-maxi-declaratively-configured-cli-args-to-env-vars-tool/37735

Run example.sh --some-par=42:

SOME_PAR=13 clap2env clap-config.toml $@

echo $SOME_PAR

will give

42
@dzmitry-lahoda dzmitry-lahoda changed the title feat: export ENV vars command line tool tool feat: export ENV vars command line clap2env tool Jan 4, 2024
@dzmitry-lahoda
Copy link
Author

will donate 100 USD in crypto for such tool :)

@epage
Copy link

epage commented Jan 4, 2024

I believe there is a tool that wraps clap for use in bash. Not finding it atm but on mobile.

One challenge with the suggested approach is that the tool can't modify the outside environment. It could dump a script to be sourced or it can wrap a command.

@dzmitry-lahoda
Copy link
Author

dzmitry-lahoda commented Jan 4, 2024

I believe there is a tool that wraps clap for use in bash. Not finding it atm but on mobile.

Yeah, I searched various terms, not found yet.

I am ok with Go/C/Zig/AOT compiled bytecode - as long as startup is fast.

I just found that clap seems fits as per clap-serde crate already does half of work.

@dzmitry-lahoda
Copy link
Author

dzmitry-lahoda commented Jan 4, 2024

One challenge with the suggested approach is that the tool can't modify the outside environment. It could dump a script to be sourced or it can wrap a command.

yeah, i see.

so it can be something like:

# bash is bad here, but kind of this to work
source < $(clap2nix clap-config.toml $@)

https://unix.stackexchange.com/questions/125110/how-do-i-source-another-processs-environment-variables

and other option try work:

# so not clear how process reuse shell called it - seems not great until there is 100% portable robust cargo to handle that
clap2nix clap-config.toml $@ -- echo $SOME_PAR

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

2 participants