jacobdeichert/mask

Support optional (non-required) positional arguments

jacobdeichert opened this issue ยท 10 comments

Required arguments use the round brackets like (required_arg) so optional args can probably use square brackets [optional_arg].

## say [phrase]

~~~sh
if [[ $phrase != "" ]]; then
    echo "$phrase"
else
    echo "๐Ÿ˜ถ"
fi
~~~

I'll take this one sometime this week.

I would suggest (arg_name?) where the question denotes optional, much like in TypeScript types.

Hmmm, i like that idea. That would make it very easy to tell what's optional and what's not.

kivio commented

it will be good if we can provide default value

I would suggest following traditional shell syntax for brackets: [optional]

I would suggest following traditional shell syntax for brackets: [optional]

Yeah, agree that sticking with traditional shell syntax is better โ€“ going to go with [optional] instead of (optional?) ๐Ÿ‘

it will be good if we can provide default value

Maybe like this: [optional=default_value] ?

Still thinking about this... named flags don't have support for a default value yet either. If we add it here, we should add to named flags as well.

Could also do traditional shell syntax for mandatory args: <required> as opposed to current (required)

Could also do traditional shell syntax for mandatory args: <required> as opposed to current (required)

Yeah, I originally had that but then changed it in #16 because a few markdown renderers I noticed were interpreting <required> args as html :/

I might have to take another look at that and see which renderers (like GitHub, or VS Code markdown preview) break... can't remember off the top of my head.

Maybe like this: [optional=default_value]?

If we add it here, we should add to named flags as well.

These both make sense. Just make sure to only set default values for optional args not required ones!