#!/usr/bin/env python3
# Copyright (c) 2019 Arista Networks, Inc.  All rights reserved.
# Arista Networks, Inc. Confidential and Proprietary.

from __future__ import absolute_import, division, print_function
import socket
import sys
import telnetlib

# pylint: disable-msg=bare-except

cmd = ' '.join( sys.argv[1:] )
prompt = 'GateD-.*>'
try:
   t = telnetlib.Telnet( 'localhost', 616 )
   t.expect( [ prompt ] )
   t.write( cmd + '\r\n' )
   # pylint: disable-next=consider-using-f-string
   full_prompt = 'GateD-%s>' % socket.gethostname()
   ( _, _, output ) = t.expect( [ prompt ] )
   print( output.strip( full_prompt ).strip() )
except:
   print( 'Failed to run %s' % cmd ) # pylint: disable=consider-using-f-string
