slap icon indicating copy to clipboard operation
slap copied to clipboard

Find a way to not have slap-variables conflict with user-variables

Open ngirard opened this issue 3 years ago • 3 comments

Hi, there are enough examples to get started with Slap, but I'm left with unanswered questions about how the variables are named.

Take the first example, with an argument named username: why is the associated variable named _username_vals rather than username ? Are there any benefits for the extra _...._vals ? Are these benefits worth the loss in readability ? Does the leading underscore mean that _username_vals shouldn't be used directly ? If so, why ?

Cheers, and thanks for your work !

ngirard avatar Nov 04 '20 23:11 ngirard

The leading _ is configurable.

cargo r -q -- parse bash prefix_ -- fast <complete.yml gives you:

prefix_success='true'
prefix_usage='USAGE:
    yml_app [FLAGS] [OPTIONS] [--] [pos]'
prefix_pos_occurs='1'
prefix_pos_indices=('1')
prefix_pos_vals=('fast')

cargo r -q -- parse bash -- fast <complete.yml gives you:

success='true'
usage='USAGE:
    yml_app [FLAGS] [OPTIONS] [--] [pos]'
pos_occurs='1'
pos_indices=('1')
pos_vals=('fast')

I normally use _ to separate slap variables and non-slap variables.
In fact the extra _vals is not necessary, we could even remove it.

guardam avatar Nov 06 '20 13:11 guardam

Ok actually I've thought about it a bit more and if we remove _vals, then if you have an option called success for example, it will conflict with slap's success variable.

guardam avatar Nov 06 '20 13:11 guardam

We should find a way to not have user-variables conflict with slap-variables

guardam avatar Nov 06 '20 13:11 guardam