ArgumentCountValid() public static method

public static ArgumentCountValid ( ICommand command ) : bool
command ICommand
return bool
Esempio n. 1
0
        public static void NuMain(StringBuilder b, string path, Func <ICommandManager, ICommand> commandBuilder)
        {
            var lastOut    = Console.Out;
            var fileSystem = new PhysicalFileSystem(path ?? Directory.GetCurrentDirectory());

            try
            {
                Console.SetOut(new ConsoleWriter(b));
                RemoveOldFile(fileSystem);
                var program = new NuProgram();
                _initializeMethod.Invoke(program, new[] { fileSystem });
                HttpClient.DefaultCredentialProvider = new ConsoleCredentialProvider();
                foreach (var command2 in program.Commands)
                {
                    program.Manager.RegisterCommand(command2);
                }
                var command = commandBuilder(program.Manager);
                if (!NuProgram.ArgumentCountValid(command))
                {
                    var commandName = command.CommandAttribute.CommandName;
                    Console.WriteLine("InvalidArguments", commandName);
                    program.HelpCommand.ViewHelpForCommand(commandName);
                }
                else
                {
                    command.Execute();
                }
            }
            finally { Console.SetOut(lastOut); }
        }
Esempio n. 2
0
        public static int Main(string[] args)
        {
            try {
                // Remove NuGet.exe.old
                RemoveOldFile();

                // Import Dependecies
                var p = new Program();
                p.Initialize();


                // Add commands to the manager
                foreach (ICommand cmd in p.Commands)
                {
                    p.Manager.RegisterCommand(cmd);
                }

                CommandLineParser parser = new CommandLineParser(p.Manager);

                // Parse the command
                ICommand command = parser.ParseCommandLine(args) ?? p.HelpCommand;

                // Fallback on the help command if we failed to parse a valid command
                if (!p.ArgumentCountValid(command))
                {
                    // Get the command name and add it to the argumet list of the help command
                    string commandName = command.CommandAttribute.CommandName;

                    // Print invalid command then show help
                    Console.WriteLine(NuGet.Common.NuGetResources.InvalidArguments, commandName);

                    p.HelpCommand.ViewHelpForCommand(commandName);
                }
                else
                {
                    command.Execute();
                }
            }
            catch (Exception e) {
                var currentColor = ConsoleColor.Gray;
                try {
                    currentColor            = Console.ForegroundColor;
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Error.WriteLine(e.Message);
                }
                finally {
                    Console.ForegroundColor = currentColor;
                }
                return(1);
            }
            return(0);
        }
Esempio n. 3
0
        public static int Main(string[] args)
        {
            try {
                // Remove NuGet.exe.old
                RemoveOldFile();

                // Import Dependecies
                var p = new Program();
                p.Initialize();

                // Add commands to the manager
                foreach (ICommand cmd in p.Commands) {
                    p.Manager.RegisterCommand(cmd);
                }

                CommandLineParser parser = new CommandLineParser(p.Manager);

                // Parse the command
                ICommand command = parser.ParseCommandLine(args) ?? p.HelpCommand;

                // Fallback on the help command if we failed to parse a valid command
                if (!p.ArgumentCountValid(command)) {
                    // Get the command name and add it to the argumet list of the help command
                    string commandName = command.CommandAttribute.CommandName;

                    // Print invalid command then show help
                    Console.WriteLine(NuGet.Common.NuGetResources.InvalidArguments, commandName);

                    p.HelpCommand.ViewHelpForCommand(commandName);
                }
                else {
                    command.Execute();
                }
            }
            catch (Exception e) {
                var currentColor = ConsoleColor.Gray;
                try {
                    currentColor = Console.ForegroundColor;
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Error.WriteLine(e.Message);
                }
                finally {
                    Console.ForegroundColor = currentColor;
                }
                return 1;
            }
            return 0;
        }