#!/usr/bin/env python
# Copyright (c) 2005-2015 Arista Networks, Inc.  All rights reserved.
# Arista Networks, Inc. Confidential and Proprietary.

# W0406:Module import itself
# E1101:Module 'SimpleCapiApi' has no 'run' member
# pylint: disable-msg=W0406
# pylint: disable-msg=E1101

import simplejson
import sys
import SimpleCapiApi

if __name__ == '__main__':

   argv = sys.argv[1:]
   inputstr = " ".join( a for a in argv )
   cmdList = [ c.strip() for c in inputstr.split(" , ") ]
   cmdStr = "\n".join( c for c in cmdList ) 
   result = SimpleCapiApi.run( cmdStr )
   rlen = len( cmdList ) + 1 # first line is extra: the status: OK / ERROR
   resultList = result.split("\n")
   print resultList[ 0 ]
   for i in range( 1, rlen ):
      print "---", i, ":", cmdList[ i-1 ]
      try: # we don't get response lines for lines after the error, if any
         s = eval( resultList[ i ] )
         print simplejson.dumps( s, sort_keys=False, indent=4 )
      except IndexError:
         print "N/A"

