Hejsil / zig-clap

Command line argument parsing library
MIT License
939 stars 67 forks source link

[request] Using `:` as an assignment separator like `=` #131

Closed heysokam closed 3 months ago

heysokam commented 3 months ago

Hi there, First timer here, and in Zig

I'm used to Nim, where you can define variables like --thing:val, and I really like that syntax. But zig-clap doesn't seem to support it from what I've seen/understood so far. So I was wondering: How feasible would it be to extend the library to support it? Or would it just be rejected because of some design philosophy/choices?

Curious what your thoughts are on the idea.

Hejsil commented 3 months ago

Would this be something where you replace = with :, or allow both? Either way, I'm not against this being configurable with the default being status quo.

Hejsil commented 3 months ago

Could have an API like this:

var res = clap.parse(clap.Help, &params, clap.parsers.default, .{
    .diagnostic = &diag,
    .allocator = gpa.allocator(),
    .assignment_separators = "=:", // &.{ '=', ':' } Might be more readable :^)
});
heysokam commented 3 months ago

Either allowing both by default or configurable. Whatever is easiest to implement, I don't mind too much.

Hejsil commented 3 months ago

As far as feasibility goes, only two lines of logic needs to be changed.

https://github.com/Hejsil/zig-clap/blob/master/clap/streaming.zig#L71 https://github.com/Hejsil/zig-clap/blob/master/clap/streaming.zig#L145

The rest of the changes will be passing around the assignment_separators option.

Hejsil commented 3 months ago

Either allowing both by default or configurable.

I want to keep the current behavior as default, but allow for it to be configured.

Hejsil commented 3 months ago

@heysokam Have a look if this is what you had in mind ^

heysokam commented 3 months ago

@Hejsil @heysokam Have a look if this is what you had in mind ^

That's epic, didn't know you would actually do it! Tysm :+1: :+1: