Esempio n. 1
0
        private ISettingsReaderResult FindSettingsFor(ICommand cmd)
        {
            string settings = File.ReadAllText($"{ExecutingDirectoryLocation}\\appsettings.json");
            var    result   = (SettingsFileReaderResult)_fileReader.Read(settings);

            // TODO(Logan) -> I should figure out a better way to handle when results aren't found.
            ISettingsReaderResult foundResult = result.Settings
                                                .Where(s => s.CommandName == cmd.CliCommandName)
                                                .SingleOrDefault();

            return(foundResult ?? new EmptySettingsReaderResult(cmd.CliCommandName));
        }
Esempio n. 2
0
 public bool Execute(string commandArguments = "", ISettingsReaderResult settingsResult = null)
 {
     try {
         ICommand[] commands = _commandFinder.FindAll();
         string     helpText = String.Join("\n", commands.Select(x => x.HelpText + Environment.NewLine).ToArray());
         _displayManager.Show(new HelpPage(helpText));
         return(true);
     }
     catch (Exception) {
         return(false);
     }
 }
Esempio n. 3
0
        public void Run(string[] args)
        {
            if (args.Length == 0)
            {
                throw new Exception("No arguments passed in");
            }
            string cmdStr  = args[0];
            string appArgs = String.Join(" ", args.Skip(1));

            _availableCommands.TryGetValue(cmdStr, out ICommand cmd);
            if (cmd == null)
            {
                throw new Exception($"Unable to find command '{cmdStr}'");
            }
            ISettingsReaderResult settingsResult = FindSettingsFor(cmd);
            bool success = Execute(cmd, appArgs, settingsResult);

            if (!success)
            {
                throw new Exception($"Unable to execute command '{cmdStr}'");
            }
        }
Esempio n. 4
0
 public bool Execute(string args, ISettingsReaderResult settingsResult) => true;
Esempio n. 5
0
 public bool Execute(string commandArguments, ISettingsReaderResult settingsResult) => true;
Esempio n. 6
0
 private bool Execute(ICommand cmd, string arguments, ISettingsReaderResult cmdSettings)
 {
     Console.WriteLine($"\nExecuting '{cmd.GetType().Name}'...\n");
     return(cmd.Execute(arguments, cmdSettings));
 }