I have the following scenario for command line argument. If there is a particular option then there should be some other required options. For example if there is -- create then there should be --name. Also if there is --remove then there should be --id. Is it possible to implement this scenario with argparse? or someother thing?
2 Answers
This can be done with subcommands as long as you don't mind create and remove not being preceded with hyphens. This may make sense anyway, since those verbs are often used as actions rather than options.
1 Comment
intuited
@bonzi: Cheers. Don't forget to accept the answer if it does end up being the solution to your problem.
Optional is implicit, required must be specified:
http://docs.python.org/library/argparse.html#required
That said, there doesn't appear to be a built-in mechanism for argument "dependencies", as I think you would like to implement. This would be a requirement for your application.