title: python-click: dependent options on another option
body: <p>This question is about the <a href="https://click.palletsprojects.com/en/7.x/" rel="noreferrer">click</a> package: I want to setup my command so that  some <code>optional options</code> are dependent on a specific option value and are required based on its value.</p>
  
  <p><strong>Required options:</strong></p>
  
  <ol>
  <li>input (input file)</li>
  <li>doe (integer , represents algo name)</li>
  </ol>
  
  <p><strong>Sub options:</strong>
  if doe is</p>
  
  <ol>
  <li>equal to <code>1</code> then <strong>option</strong> <code>generator_string</code> should become <code>required=True</code></li>
  <li>equal to <code>2</code> then <strong>option</strong> <code>number_of_sample_points</code>should become <code>required=True</code></li>
  <li>equal to <code>3</code> then <strong>option</strong> <code>number_of_center_points</code>should become <code>required=True</code></li>
  </ol>
  
  <p><strong>Valid Examples:</strong></p>
  
  <ol>
  <li><code>--input ./input.txt --doe 1 --generator_string 1234</code></li>
  <li><code>--input ./input.txt --doe 2 --number_of_sample_points 3</code></li>
  <li><code>--input ./input.txt --doe 3 --number_of_center_points 2</code></li>
  </ol>
  
  <p><strong>CODE:</strong>  </p>
  
  <pre class="lang-py prettyprint-override"><code>import click
  
  
  def check_output(ctx, param, value):
      if value == 1:
          if not ctx.params['generator_string']:
              setOptionAsRequired(ctx, 'generator_string')
      return value
  
  
  def setOptionAsRequired(ctx, name):
      for p in ctx.command.params:
          if isinstance(p, click.Option) and p.name == name:
              p.required = True
  
  
  @click.option('--input', required=True, type=click.Path(exists=True) )
  @click.option('--doe', required=True, type=int, callback=check_output )
  @click.option('--generator_string', required=False, type=str, is_eager=True)
  @click.option('--number_of_sample_points', required=False, type=int, is_eager=True)
  @click.option('--number_of_center_points', required=False, type=int, is_eager=True)
  @click.command(context_settings=dict(max_content_width=800))
  def main(input, doe, generator_string, number_of_sample_points, number_of_center_points):
      click.echo('is valid command')
  
  if __name__ == '__main__':
      main()
  </code></pre>