#!/usr/bin/env python3
# Copyright (c) 2011 Arista Networks, Inc.  All rights reserved.
# Arista Networks, Inc. Confidential and Proprietary.
#
# This cli is strictly meant to be used as the default shell for
# internal login sessions on modular systems

import os, sys, Cell

# To prevent other users from running it on bash
if os.geteuid() != 90:
   sys.exit( '% Permission denied\n' )

args = [ sys.executable, '/usr/bin/CliShell', '--sysname', 'ar', '--disable-aaa',
         '--privilege', '15' ]

# Check if the user specified a command
if len( sys.argv ) > 1:
   # Only '-c' is supported
   if sys.argv[ 1 ] in ( '-c', '--command' ):
      args += [ sys.argv[ 1 ], ' '.join( sys.argv[ 2: ] ).strip( '\"\'' ) ]
   else:
      sys.exit( '% Invalid input: ' + ' '.join( sys.argv[ 1: ] ) )

try:
   # We can only be called on standby, so we know the peer is active.
   peerId = Cell.activeCell()
   # pylint: disable-next=consider-using-f-string
   os.environ[ 'CLI_PROMPT_PREFIX' ] = 's%d:' % peerId
   os.execv( args[ 0 ], args )
except Exception as e: # pylint: disable=broad-except
   sys.exit( e )
