public void Execute(IEnumerable <string> paramList) { if (paramList.Count() != 3) { throw new ArgumentException(); } var parameters = paramList.Skip(1).ToList(); var pathValue = new PathValue { Name = parameters[0], Path = parameters[1] }; try { _service.AddPathValue(pathValue); var pathLedgerService = new PathLedgerService(); pathLedgerService.AddEntry(pathValue); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public void AddPathEntryCommand(CommandLineApplication app) { app.Command("add", (cmd) => { cmd.HelpOption("-?|-h|--help"); var name = cmd.Argument( "name", "The name of the Path Entry", false ); var path = cmd.Argument( "path", "the path to the directory", false ); cmd.Description = "Add a new entry to the System Environment Variable Path"; cmd.OnExecute(() => { if (name.Value == null || path.Value == null) { Console.WriteLine("a name and path must be supplied!"); cmd.ShowHelp(); return(1); } var patherService = new PatherService(); var pathValue = new PathValue { Name = name.Value, Path = path.Value }; patherService.AddPathValue(pathValue); Console.WriteLine($"Saving Name: {name.Value} path:{path.Value}"); return(0); }); }); }