mask icon indicating copy to clipboard operation
mask copied to clipboard

Support optional (non-required) positional arguments

Open jacobdeichert opened this issue 5 years ago • 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
~~~

jacobdeichert avatar Jul 12 '19 03:07 jacobdeichert

I'll take this one sometime this week.

jacobdeichert avatar Jul 22 '19 04:07 jacobdeichert

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

brandonkal avatar Mar 18 '20 22:03 brandonkal

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

jacobdeichert avatar Mar 19 '20 02:03 jacobdeichert

it will be good if we can provide default value

kivio avatar Mar 04 '21 09:03 kivio

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

brendanfalk avatar Apr 16 '21 19:04 brendanfalk

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?) 👍

jacobdeichert avatar Apr 17 '21 13:04 jacobdeichert

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.

jacobdeichert avatar Apr 17 '21 13:04 jacobdeichert

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

brendanfalk avatar Apr 17 '21 18:04 brendanfalk

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.

jacobdeichert avatar Apr 17 '21 18:04 jacobdeichert

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!

brendanfalk avatar Apr 17 '21 18:04 brendanfalk