public int Execute(string commandLine, IEnumerable<string> optionalInputs)
        {
            commandLine = commandLine.Trim();
            if (commandLine == string.Empty) return 0;
            string commandParameters = commandLine;
            var command = _handlers.Select(x => x.Execute(ref commandParameters)).Where(x => x != null).FirstOrDefault();
            if (command == null)
            {
                var sp = commandLine.IndexOf(" ");

                _formatter.Render(new Error("The term '{0}' is not a recognized command or alias. Check the spelling or enter 'get-help' to get a list of available commands.",
                           sp != -1 ? commandLine.Substring(0, sp) : commandLine));
                return -10;
            }
            int returnCode = 0;
            var commandLineRunner = new CommandLineRunner { OptionalInputs = optionalInputs };
            using (DownloadNotifier())
            using (_eventHub.Subscribe<ICommandOutput>(_formatter.Render))
            {
                foreach (var output in commandLineRunner.Run(command, commandParameters))
                {
                    _eventHub.Publish(output);
                    if (output.Type == CommandResultType.Error)
                    {
                        returnCode = -50;
                    }
                }

            }
            return returnCode;
        }
Exemplo n.º 2
0
        public int Execute(string commandLine, IEnumerable <string> optionalInputs)
        {
            commandLine = commandLine.Trim();
            if (commandLine == string.Empty)
            {
                return(0);
            }
            string commandParameters = commandLine;
            var    command           = _handlers.Select(x => x.Execute(ref commandParameters)).Where(x => x != null).FirstOrDefault();

            if (command == null)
            {
                var sp = commandLine.IndexOf(" ");

                _formatter.Render(new Error("The term '{0}' is not a recognized command or alias. Check the spelling or enter 'get-help' to get a list of available commands.",
                                            sp != -1 ? commandLine.Substring(0, sp) : commandLine));
                return(-10);
            }
            int returnCode        = 0;
            var commandLineRunner = new CommandLineRunner {
                OptionalInputs = optionalInputs
            };

            using (_eventHub.Subscribe <ICommandOutput>(_formatter.Render))
                foreach (var output in commandLineRunner.Run(command, commandParameters))
                {
                    _eventHub.Publish(output);
                    if (output.Type == CommandResultType.Error)
                    {
                        returnCode = -50;
                    }
                }
            return(returnCode);
        }
Exemplo n.º 3
0
        public int Execute(string commandLine, IEnumerable<string> optionalInputs)
        {
            commandLine = commandLine.Trim();
            if (commandLine == string.Empty) return 0;
            string commandParameters = commandLine;
            var command = _handlers.Select(x => x.Execute(ref commandParameters)).Where(x=>x != null).FirstOrDefault();
            if (command == null)
            {
                var sp = commandLine.IndexOf(" ");

                WriteError("The term '{0}' is not a recognized command or alias. Check the spelling or enter 'get-help' to get a list of available commands.", sp != -1 ? commandLine.Substring(0, sp) : commandLine);
                return -10;
            }
            int returnCode = 0;
            var commandLineRunner = new CommandLineRunner() { OptionalInputs = optionalInputs };
            foreach (var output in commandLineRunner.Run(command, commandParameters))
            {
                using (ColorFromOutput(output))
                    Console.WriteLine(output.ToString());
                if (output.Type == CommandResultType.Error)
                {
                    returnCode = -50;
                }
            }
            return returnCode;
        }
Exemplo n.º 4
0
        public int Execute(string commandLine, IEnumerable <string> optionalInputs)
        {
            commandLine = commandLine.Trim();
            if (commandLine == string.Empty)
            {
                return(0);
            }
            string commandParameters = commandLine;
            var    command           = _handlers.Select(x => x.Execute(ref commandParameters)).Where(x => x != null).FirstOrDefault();

            if (command == null)
            {
                var sp = commandLine.IndexOf(" ");

                WriteError("The term '{0}' is not a recognized command or alias. Check the spelling or enter 'get-help' to get a list of available commands.", sp != -1 ? commandLine.Substring(0, sp) : commandLine);
                return(-10);
            }
            int returnCode        = 0;
            var commandLineRunner = new CommandLineRunner()
            {
                OptionalInputs = optionalInputs
            };

            foreach (var output in commandLineRunner.Run(command, commandParameters))
            {
                using (ColorFromOutput(output))
                    Console.WriteLine(output.ToString());
                if (output.Type == CommandResultType.Error)
                {
                    returnCode = -50;
                }
            }
            return(returnCode);
        }
Exemplo n.º 5
0
        public override bool Execute()
        {
            if (Debug) Debugger.Launch();

            var runner = new CommandLineRunner();

            var commands = ReadCommands(_environment);

            var command = commands.FirstOrDefault(x => x.Noun.EqualsNoCase(Noun) && x.Verb.EqualsNoCase(Verb));
            if (command == null)
            {
                Log.LogError("Command named '{0}-{1}' is not a recognized command.", Verb, Noun);
                return false;
            }
            foreach (var value in runner.Run(command, GetArguments()))
                ProcessOutput(value);

            return _success;
        }
Exemplo n.º 6
0
        public override bool Execute()
        {
            if (Debug) Debugger.Launch();

            var runner = new CommandLineRunner();

            var commands = ReadCommands(_environment);

            var command = commands.FirstOrDefault(x => x.Noun.EqualsNoCase(Noun) && x.Verb.EqualsNoCase(Verb));
            if (command == null)
            {
                Log.LogError("Command named '{0}-{1}' is not a recognized command.", Verb, Noun);
                return false;
            }
            var captures = (Capture ?? string.Empty).Split(';') ;
            var captureResult = new List<ITaskItem>();
            foreach (var value in runner.Run(command, GetArguments()))
            {
                ProcessOutput(value);
                CaptureOutput(value, captures, captureResult);
            }
            Captures = captureResult.ToArray();
            return _success;
        }