protected override bool CheckUnusedEnvironmentVariables(ClientOptions options) { return(true); }
public override int Execute(ClientController controller, ClientOptions options) { controller.TakeSnapshot(options.Values[1]); return(0); }
protected override bool CheckValues(ClientOptions options) { return(Check(options.Values.Count >= 2, "Missing command to execute.")); }
public static int Main(string[] args) { try { var options = new ClientOptions(); var parser = new CommandLineParser(); if (!parser.ParseArguments(args, options, Console.Error)) { return(1); } if (options.Values == null || options.Values.Count == 0) { PrintErrorMessageAndHelp(options, "Must specify a command."); return(1); } string commandName = options.Values[0]; Command command = CreateCommand(commandName); if (command == null) { PrintErrorMessageAndHelp(options, "Unrecognized command name."); return(1); } bool haveMaster = options.Master != null; bool haveProfile = options.Configuration != null || options.Profile != null; if (haveMaster && haveProfile || !haveMaster && !haveProfile || (options.Configuration != null) != (options.Profile != null)) { PrintErrorMessageAndHelp(options, "Must specify either --master or both --configuration and --profile."); return(1); } Profile profile; if (options.Configuration != null && options.Profile != null) { XmlConfiguration xmlConfiguration = ConfigurationFileHelper.LoadConfiguration(options.Configuration); XmlProfile xmlProfile = xmlConfiguration.GetProfileById(options.Profile); if (xmlProfile == null) { PrintErrorMessageAndHelp(options, "Profile not found in configuration file."); return(1); } profile = xmlProfile.ToProfile(); } else { profile = new Profile() { Master = options.Master, MasterPort = options.MasterPort, Slave = options.Slave, SlavePort = options.SlavePort, VM = options.VM, Snapshot = options.Snapshot }; } if (!command.Validate(profile, options)) { return(1); } using (var controller = new ClientController(profile)) { controller.Quiet = options.Quiet; controller.ConnectionTimeout = TimeSpan.FromSeconds(options.ConnectionTimeout); try { return(command.Execute(controller, options)); } catch (OperationFailedException ex) { Console.Error.WriteLine("Operation failed."); Console.Error.WriteLine(ex.Why); if (ex.__isset.details) { Console.Error.WriteLine("Details:"); Console.Error.WriteLine(ex.Details); } return(1); } } } catch (Exception ex) { Console.WriteLine("Fatal exception: " + ex); return(1); } }
protected override bool CheckValues(ClientOptions options) { return(Check(options.Values.Count >= 2, "Missing new snapshot name.") && Check(options.Values.Count == 2, "Found excess arguments.")); }
protected override bool CheckValues(ClientOptions options) { return(Check(options.Values.Count >= 3, "Missing files to copy.") && Check(options.Values.Count == 3, "Found excess arguments.")); }
protected override bool CheckUnusedForce(ClientOptions options) { return(true); }
protected virtual bool CheckUnusedWorkingDirectory(ClientOptions options) { return(Check(options.WorkingDirectory == null, "--dir is not used by this command.")); }
protected virtual bool CheckUnusedTimeout(ClientOptions options) { return(Check(options.Timeout == 0, "--timeout is not used by this command.")); }
protected virtual bool CheckUnusedForce(ClientOptions options) { return(Check(!options.Force, "--force is not used by this command.")); }
protected virtual bool CheckUnusedEnvironmentVariables(ClientOptions options) { return(Check(options.EnvironmentVariables == null || options.EnvironmentVariables.Length == 0, "--env is not used by this command.")); }
protected virtual bool CheckUnusedRecursive(ClientOptions options) { return(Check(!options.Recursive, "--recursive is not used by this command.")); }
protected virtual bool CheckValues(ClientOptions options) { return(Check(options.Values.Count == 1, "Found excess arguments.")); }
public abstract int Execute(ClientController controller, ClientOptions options);
protected override bool CheckUnusedWorkingDirectory(ClientOptions options) { return(true); }
public override bool Validate(Profile profile, ClientOptions options) { return(base.Validate(profile, options) && Check(profile.VM != null, "--vm or --profile required for this command.")); }
protected override bool CheckUnusedTimeout(ClientOptions options) { return(true); }
public override int Execute(ClientController controller, ClientOptions options) { controller.PowerOff(); return(0); }
protected override bool CheckUnusedRecursive(ClientOptions options) { return(true); }
public override int Execute(ClientController controller, ClientOptions options) { controller.SaveState(); return(0); }
public override int Execute(ClientController controller, ClientOptions options) { controller.CopyFromVM(options.Values[1], options.Values[2], options.Recursive, options.Force); return(0); }
private static void PrintErrorMessageAndHelp(ClientOptions options, string message) { Console.Error.WriteLine(message); Console.Error.WriteLine(); Console.Error.WriteLine(options.GetUsage()); }