Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support optional (non-required) positional arguments #5

Open
jacobdeichert opened this issue Jul 12, 2019 · 10 comments · May be fixed by #109
Open

Support optional (non-required) positional arguments #5

jacobdeichert opened this issue Jul 12, 2019 · 10 comments · May be fixed by #109
Assignees
Labels
enhancement New feature or request

Comments

@jacobdeichert
Copy link
Owner

jacobdeichert commented Jul 12, 2019

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
Copy link
Owner Author

I'll take this one sometime this week.

@brandonkal
Copy link

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

@jacobdeichert
Copy link
Owner Author

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

@kivio
Copy link

kivio commented Mar 4, 2021

it will be good if we can provide default value

@brendanfalk
Copy link

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

@jacobdeichert
Copy link
Owner Author

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
Copy link
Owner Author

jacobdeichert commented Apr 17, 2021

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.

@brendanfalk
Copy link

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

@jacobdeichert
Copy link
Owner Author

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.

@brendanfalk
Copy link

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!

@jpal91 jpal91 linked a pull request May 9, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants