-
Notifications
You must be signed in to change notification settings - Fork 42
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
[DAR-2294][External] Made text a required argument when posting comments through CLI #850
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make an argument required, we can just pass required=True
as one of it's argument
import argparse
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--text", type=str, help="Comment: list of words", required=True)
args = parser.parse_args()
print(args)
$ python t3.py
usage: t3.py [-h] --text TEXT
t3.py: error: the following arguments are required: --text
$ python t3.py --text 1
Namespace(text='1')
@saurbhc I thought about this approach, but in the example you shared if you run
Implying that text is optional, not required |
Hm, that's argparse's default logic of considering arguments starting with I suspect changing the Idk if creating a required argument group would be over-engineering this? 🤔 import argparse
if __name__ == "__main__":
parser = argparse.ArgumentParser()
required_grp = parser.add_argument_group("required arguments")
required_grp.add_argument("--text", type=str, help="Comment: list of words", required=True)
args = parser.parse_args()
print(args) $ python t3.py --help
usage: t3.py [-h] --text TEXT
options:
-h, --help show this help message and exit
required arguments:
--text TEXT Comment: list of words |
@saurbhc Damn that's annoying, this thread from 2010 explains why this wasn't changed Having read that Stack Overflow thread, I think adding argument groups is probably needlessly complicated. I think I can live with
Therefore have simply passed |
Problem
When posting dataset item comments through the CLI, the text argument should be required. Not providing the text argument with a value causes the API request to post the comment to fail
Solution
Make the text argument required instead
Changelog
Made the comment text argument required when posting dataset item comments through the CLI