Ejemplo n.º 1
0
        protected override async Task <int> Validate()
        {
            var baseValidation = await base.Validate().ConfigureAwait(false);

            if (baseValidation != StandardExitCodes.ErrorSuccess)
            {
                return(baseValidation);
            }

            if (this.Verb.File == null)
            {
                if (!this.commands.Any())
                {
                    await this.Console.WriteError("At least one command must be passed.").ConfigureAwait(false);

                    return(StandardExitCodes.ErrorGeneric);
                }
            }
            else if (File.Exists(this.Verb.File))
            {
                if (!this.commands.Any())
                {
                    await this.Console.WriteError("The file contains no commands.").ConfigureAwait(false);
                }
            }
            else
            {
                await this.Console.WriteError($"The file '{this.Verb.File}' does not exist.").ConfigureAwait(false);

                return(StandardExitCodes.ErrorGeneric);
            }

            var factory = new VerbExecutorFactory(new ConsoleImpl(System.Console.Out, System.Console.Error));

            foreach (var line in this.commands)
            {
                var parsedArgs = NativeMethods.ConvertArgumentsStringToArray(line.Trim());

                try
                {
                    factory.ThrowIfInvalidArguments(parsedArgs, true);
                }
                catch (VerbExecutorFactory.ArgumentsParsingException ape)
                {
                    await this.Console.WriteError("The following line could not be parsed: " + line).ConfigureAwait(false);

                    foreach (var err in ape.Errors)
                    {
                        await this.Console.WriteError("  * " + err).ConfigureAwait(false);
                    }

                    return(StandardExitCodes.ErrorParameter);
                }
            }

            return(StandardExitCodes.ErrorSuccess);
        }
Ejemplo n.º 2
0
        private static async Task <int> DoCommonVerbs(IEnumerable <string> args, IConsole console)
        {
            var factory      = new VerbExecutorFactory(console);
            var verbExecutor = factory.CreateStandardVerbExecutor(args);

            if (verbExecutor != null)
            {
                var exitCode = await verbExecutor.Execute().ConfigureAwait(false);

                Environment.ExitCode = exitCode;
                return(exitCode);
            }

            return(Environment.ExitCode);
        }
Ejemplo n.º 3
0
        private static async Task <int> DoEditVerb(string packagePath, IEnumerable <string> args, IConsole console)
        {
            var factory = new VerbExecutorFactory(console);

            var verbExecutor = factory.CreateEditVerbExecutor(packagePath, args);

            if (verbExecutor != null)
            {
                var exitCode = await verbExecutor.Execute().ConfigureAwait(false);

                Environment.ExitCode = exitCode;
                return(exitCode);
            }

            return(Environment.ExitCode);
        }
Ejemplo n.º 4
0
        protected override async Task <int> ExecuteOnExtractedPackage(string directoryPath)
        {
            foreach (var line in this.commands)
            {
                try
                {
                    var parsedArgs = NativeMethods.ConvertArgumentsStringToArray(line.Trim());

                    var factory  = new VerbExecutorFactory(new ConsoleImpl(System.Console.Out, System.Console.Error));
                    var executor = factory.CreateEditVerbExecutor(directoryPath, parsedArgs, true);
                    if (executor == null)
                    {
                        return(StandardExitCodes.ErrorGeneric);
                    }

                    Environment.ExitCode = await executor.Execute().ConfigureAwait(false);

                    if (Environment.ExitCode != StandardExitCodes.ErrorSuccess)
                    {
                        return(Environment.ExitCode);
                    }
                }
                catch (VerbExecutorFactory.ArgumentsParsingException ape)
                {
                    await this.Console.WriteError("The following line could not be parsed: " + line).ConfigureAwait(false);

                    foreach (var err in ape.Errors)
                    {
                        await this.Console.WriteError("  * " + err).ConfigureAwait(false);
                    }

                    return(StandardExitCodes.ErrorParameter);
                }
                catch (Exception)
                {
                    await this.Console.WriteError($"Command  '{line}' could not be interpreted.").ConfigureAwait(false);

                    return(StandardExitCodes.ErrorGeneric);
                }
            }
            return(StandardExitCodes.ErrorSuccess);
        }