title: Getopt multiple argument syntaxes
body: <p>So I'm working on an assignment in a python class that I'm taking, but have gotten stuck with something I can't really find any further information about (neither on SO, Google or in the courseware). </p>
  
  <p>I need help with how to handle arguments with multiple types of syntaxes - like  <strong>[arg] and &lt; arg ></strong>, which is something I've been unable to find any further information about.</p>
  
  <p>Here is an example use-case that SHOULD work.</p>
  
  <pre><code>&gt;&gt;&gt; ./marvin-cli.py --output=&lt;filename.txt&gt; ping &lt;http://google.com&gt;
  &gt;&gt;&gt; Syntax error near unexpected token 'newline'
  </code></pre>
  
  <p>The below code works fine for any use-case where I haven't defined any further output than writing to the console:</p>
  
  <pre><code># Switch through all options
  try:
  
      opts, args = getopt.getopt(sys.argv[1:], "hsv", ["help","version","silent", "get=", "ping=", "verbose", "input=", "json"])
      for opt, arg in opts:
          if opt in ("-h", "--help"):
              printUsage(EXIT_SUCCESS)
          elif opt in ("-s", "--silent"):
              VERBOSE = False 
          elif opt in ("--verbose"):
              VERBOSE = True 
          elif opt in ("--ping"):
              ping(arg)
          elif opt in ("--input"):
              print("Printing to: ", arg)
          else:
              assert False, "Unhandled option"
  
  
  except Exception as err:
      print("Error " ,err)
      print(MSG_USAGE)
      # Prints the callstack, good for debugging, comment out for production
      #traceback.print_exception(Exception, err, None)
      sys.exit(EXIT_USAGE)
  #print(sys.argv[1])
  </code></pre>
  
  <p>Example usage:</p>
  
  <pre><code>&gt;&gt;&gt; ./marvin-cli.py ping http://google.com
  &gt;&gt;&gt; Latency 100ms
  </code></pre>
  
  <p>And this is a snippet showing how the ping works:</p>
  
  <pre><code>def ping(URL):
      #Getting necessary imports
      import requests
      import time
  
      #Setting up variables
      start = time.time()
      req = requests.head(URL)
      end = time.time()
  
      #printing result
      if VERBOSE == False:
          print("I'm pinging: ", URL)
          print("Received HTTP response (status code): ", req.status_code)
  
      print("Latency: {}ms".format(round((end - start) * 1000, 2)))
  </code></pre>