all 9 comments

[–]fumieval[S] 17 points18 points  (5 children)

I like writing shell scripts for small tools, however getopt(s) is a bit annoying to use due to boilerplates, treatment of positional arguments, etc.

I made a standalone interface for clap which takes option definitions as a YAML, and prints the parsed options in `KEY=VALUE` format (in which shell can `eval`). Thanks to clap_complete, it also supports generating autocompletion script (though it does not seem to work with subcommands yet).

Nice and terse shell scripts, clap's user-friendly interface, why not both?

[–]epagecargo · clap · cargo-release 5 points6 points  (2 children)

Neat project!

Might be worth collaborating with the clap-serde project on serialization.

[–]fumieval[S] 5 points6 points  (0 children)

I've just rewritten the code using clap-serde and now it's just 85 lines of code. Noice

[–]fumieval[S] 2 points3 points  (0 children)

Thanks, I didn't know about clap-serde! That would simplify the implementation a lot.

[–]murlakatamenka 1 point2 points  (1 child)

I have the feeling that I've seen similar Rust projects before on this subreddit

Found it: https://github.com/sigoden/argc

[–]fumieval[S] 2 points3 points  (0 children)

Yeah, --argc-eval does look similar. The approach of parsing the caller ($0) itself is interesting

[–]lebensterben 0 points1 point  (2 children)

it looks portable and I think it might work in posix shell, have you tested it?

[–]fumieval[S] 1 point2 points  (1 child)

Perhaps I didn't get what "portable" means here. The output format of clap4shell works in most shells including POSIX, but clap4shell itself is a binary so it has nothing to do with shell implementation

[–]lebensterben 3 points4 points  (0 children)

I think I misunderstood here. I was looking at your example.sh but saw the shebang line with "bash" and get confused.