title: Python argparse: Leading dash in argument
body: <p>I'm using Python's <a href="https://docs.python.org/3/library/argparse.html" rel="noreferrer"><code>argparse</code></a> module to parse command line arguments. Consider the following simplified example,</p>
  
  <pre><code># File test.py
  import argparse
  parser = argparse.ArgumentParser()
  parser.add_argument('-s', action='store')
  parser.add_argument('-a', action='append')
  args = parser.parse_args()
  print(args)
  </code></pre>
  
  <p>which can successfully be called like</p>
  
  <pre><code>python test.py -s foo -a bar -a baz
  </code></pre>
  
  <p>A single argument is required after <code>-s</code> and after each <code>-a</code>, which may contain spaces if we use quotation. If however an argument starts with a dash (<code>-</code>) and does not contain any spaces, the code crashes:</p>
  
  <pre><code>python test.py -s -begins-with-dash -a bar -a baz
  </code></pre>
  
  <blockquote>
    <p>error: argument -s: expected one argument</p>
  </blockquote>
  
  <p>I get that it interprets <code>-begins-with-dash</code> as the beginning of a new option, which is illegal as <code>-s</code> has not yet received its required argument. It's also pretty clear though that no option with the name <code>-begins-with-dash</code> has been defined, and so it should not interpret it as an option in the first place. How can I make <code>argparse</code> accept arguments with one or more leading dashes?</p>