title: How can I get an argument name from argparse?
body: <p>This is my command line script</p>
  
  <pre><code>import argparse
  
  
  parser = argparse.ArgumentParser('My command line app')
  
  parser.add_argument('--start', type=start, metavar='HOST', dest='result', nargs='*', default='all', help='Start hosts')
  parser.add_argument('--stop', type=stop, metavar='HOST', dest='result', nargs='*', default='all', help='Stop hosts')
  parser.add_argument('--status', type=status, metavar='HOST', dest='result', nargs='*', default='all', help='Show hosts status')
  
  args = parser.parse_args()
  </code></pre>
  
  <p>Currently I defined one function for each option, but I would like to wrap them in only one for these three options. Then I would need to know which argument was used. Is it possible with argparse?</p>
  
  <p><strong>Solution</strong></p>
  
  <p>At the end I took this way: </p>
  
  <pre><code>import argparse
  
  
  def wrapper(command, hosts):
      pass
  
  
  parser = argparse.ArgumentParser('My script')
  parser.add_argument('action', choices=['start', 'stop', 'status'], help='Action')
  parser.add_argument('hosts', metavar='HOST', nargs='*', default='all')
  
  args = parser.parse_args()
  
  wrapper(args.action, args.hosts)
  </code></pre>