How to save a previous command line argument
<p>I'm writing my first python command line tool using docopt and have run into an issue. </p>

<p>My structure is like this:</p>

<pre><code>Usage:
  my-tool configure
  my-tool [(-o &lt;option&gt; | --option &lt;option&gt;)]
  ...
</code></pre>

<p>I'm trying to find a way to run <code>my-tool -o foo-bar</code> first, and then optionally pass the value 'foo-bar' into my configure function if I run <code>my-tool configure</code> next. </p>

<p>In pseduocode, that translates to this:</p>

<pre><code>def configure(option=None):
    print option # With the above inputs this should print 'foo-bar'

def main():
    if arguments['configure']:
       configure(option=arguments['&lt;option&gt;'])
       return
    ...
</code></pre>

<p>Is there a way to get this working without changing the argument structure? 
I'm looking for a way to avoid <code>my-tool configure [(-o &lt;option&gt; | --option &lt;option&gt;)]</code></p>

<p>I tried writing some script to help you but it was a bit beyond my (current) Newbie skill level.
However, the tools/approach I started taking may be able to help. Try using <code>sys.argv</code> (which generates a list of all arguments from when the script is run), and then using some regular expressions (<code>import re</code>...).</p>

<p>I hope this helps someone else help you. (:</p>

python python-2.7 command-line-interface docopt