title: Python Argparse - conditionally required arguments based on the value of another argument
body: <p>I am trying to write a daemon service, which can be controlled in the command line. For example, to start the service</p>
  
  <p><code>python3 test.py -c start -d /mydownloadfolder/ -j /myconfig.json</code></p>
  
  <p>to stop the service, </p>
  
  <p><code>python3 test.py -c stop</code></p>
  
  <p>The <code>-d</code> <code>-j</code> parameters are required only when I start the service. Therefore, I need to implement conditionally required arguments based on the value of another argument.</p>
  
  <p>I did some search and found this useful post <a href="https://stackoverflow.com/questions/25626109/python-argparse-conditionally-required-arguments">Python Argparse conditionally required arguments</a>
  The difference is: instead of checking the existence of '--command', I need to check the value of the '--command'. </p>
  
  <p>Here is my tentative solution:</p>
  
  <pre><code>PARSER.add_argument('-c', '--command', required=True, help='provide a valid command: start, stop, restart, or status')
  NEED_MORE_ARGS = PARSER.parse_args().command.lower().startswith('start')
  PARSER.add_argument('-d', '--download', required=NEED_MORE_ARGS , default=LOCAL_DOWNLOAD, help='set account download folder')
  PARSER.add_argument('-j', '--input',  required=NEED_MORE_ARGS, default=JSON_INPUT, help='set input json file')
  </code></pre>
  
  <p>I parsed the args in the middle to get NEED_MORE_ARGS(boolean), and then add other args. The code seems not clean. Is there a better way to do this?</p>
  
  <p>==============</p>
  
  <p>Updated: The tentative solution does not work. :(</p>