title: Python invoke: Get the flags from a parent command?
body: <p>Given the following python <a href="https://docs.pyinvoke.org/en/stable/index.html" rel="nofollow noreferrer">invoke</a> script:</p>
  <pre class="lang-py prettyprint-override"><code>from invoke import task
  
  @task
  def pre(c):
     print(&quot;pre&quot;)
  
  @task(pre=[pre])
  def command(c, flag):
     print(f&quot;command flag={flag}&quot;)
  </code></pre>
  <p>Called with the following shell command:</p>
  <p><code>inv command --flag</code></p>
  <p>I would like to read the value of <code>flag</code> to conditionally do some actions in <code>pre</code>. Is there a way I can read the <code>flag</code> property passed to <code>command</code> from within <code>pre</code> using invoke's API? I couldn't find anything in the docs about it.</p>
  <p>I am aware that push comes to shove, I can import sys and read the args directly, but I'd rather avoid doing that work manually if I can.</p>