title: How can I use click to parse a string for arguments?
body: <p>Say I have a list of strings containing arguments and options, with <code>argparse</code>, I’m able to parse this list using the <code>parse_args</code> function into an object, as follows:</p>
  
  <pre><code>import argparse
  
  extra_params = [‘—sum’, ‘7’, ‘-1’, ‘42’]
  
  parser=argparse.ArgumentParser(description=“argparse docs example”)
  parser.add_argument(‘integers’, metavar=‘N’, type=int, nargs=‘+’,
                      help=‘an integer for the accumulator’)
  parser.add_argument(‘—sum’, dest=‘accumulate’, action=‘store_const’,
                      const=sum, default=max,
                      help=‘sum the integers (default: find the max)’)
  parsed_object=parser.parse_args(extra_params)
  </code></pre>
  
  <p>Here, <code>argparse</code> has parsed a provided iterable of strings. Can one use <code>click</code> to also parse a provided iterable of strings?</p>
  
  <p>I’ve searched through the API documentation for <code>click</code> and it appears that there’s a <code>parse_args</code> function within the <code>*Command</code> set of classes but don’t see anything in the docs around how I can do this. I’ve tried instantiating <code>BaseCommand</code> as well as <code>Command</code> but not sure how to get <code>parse_args</code> working without a correct context.</p>
  
  <p>For broader context, this question is a result of having built a launcher application that end users use as a scaffold to launch their own applications. Here, the launcher consumes a number of arguments for which click decorators work perfectly. Unknown arguments can be handled as shown in the documentation <a href="https://click.palletsprojects.com/en/7.x/advanced/#forwarding-unknown-options" rel="nofollow noreferrer">here</a>. This launcher then calls an end-user provided callable with these unparsed parameters. Click leaves unparsed parameters as a tuple of strings. How would the end-user, in this situation, be able to use Click to parse the argument's they're interested in? Here's a snippet to illustrate the issue:</p>
  
  <pre><code>import click
  from typing import Tuple
  
  @click.command(name="TestLauncher", context_settings={
    "ignore_unknown_options": True
  })
  @click.option('--uri', '-u',
    help="URI for the server")
  @click.argument('unprocessed_args', nargs=-1,
    type=click.UNPROCESSED)
  def main(uri: str, unprocessed_args: Tuple[str, ...]) -&gt; None:
      print(f"Was passed a URI of {uri}")
      print(f"Additional args are {unprocessed_args}")
  
      child_function(unprocessed_args)
  
  def child_function(unprocessed_args: Tuple[str, ...]) -&gt; None:
      # How do I get Click to parse the provided args for me?
      pass
  
  if __name__ == "__main__":
      # pylint: disable=no-value-for-parameter, unexpected-keyword-arg
      main()
  </code></pre>
  
  <p>Running this from the command line:</p>
  
  <pre><code>python3 so_test.py --uri test.com --prog-arg 10
  Was passed a URI of test.com
  Additional args are ('--prog-arg', '10')
  </code></pre>