Beispiel #1
0
        /**
         * Where the shell begins
         */
        public function main() {
			$this->Out->debug(__METHOD__);

			// Clear screen
			$clean_screen = false;

			// Pretty welcome splash screen
			$this->Shell->outSplashScreen(array(
				'Cloud Command Line Interpreter',
				//'$Id$',
				null,
				'Using configuration file: '.$this->config_file,
				($this->debug) ? 'Debug mode is: ON' : false,
			),$clean_screen);

			// Setup monitoring on some files that we don't want to change
			// underneath us while the shell is running
			$this->FileChangeMonitor->addMonitoredFile(array(
					$this->config_file,
					__FILE__,
					$this->Shell->self_filename,
					$this->Cloud->self_filename,
					$this->Cloud->Address->self_filename,
					$this->Cloud->Command->self_filename,
					$this->Cloud->Instance->self_filename,
					$this->Cloud->Keypair->self_filename,
					$this->Cloud->Package->self_filename,
					$this->Cloud->Volume->self_filename,
					$this->Cloud->Spot->self_filename,
			));

			// init the Shell - parses all the command meta data to ensure
			// it is valid and generates the tab completion tree data
			$this->Shell->initShell($this);

			// Setup all the cloud definitions configs
			if(!$this->initCloudDefinitions()) {
				$this->cmd_exit();
			}

			// Enter the command loop
			while(true) {

				// Obtain the users input
				$input = $this->Shell->getUserInput();

				// Check for file changes
				if($changes = $this->FileChangeMonitor->poll()) {
					$this->Out->alert('Dependent file \''.basename(array_pop(array_keys($changes))).'\' changed while '.CloudCli::SHELL_NAME.' is running - terminated!');
					$this->cmd_exit();
				}

				// Attempt to pass off to it's respective method
				if(isset($input[0]) && !empty($input[0])) {

					$method_name = 'cmd_'.$input[0];

					if(method_exists($this,$method_name)) {
						array_shift($input); // remove arg[0] because it is a reference to ourself
						call_user_func_array(array(__CLASS__,$method_name),$input);
					} else {
						$this->Shell->outCommandUnknown();
					}
				}
			}
        }