Beispiel #1
0
        public static int Main(string[] args)
        {
            var console = new Inversion.CommandLine.Infrastructure.Console();
            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 (!ArgumentCountValid(command))
            {
                // Get the command name and add it to the argument list of the help command
                string commandName = command.CommandAttribute.CommandName;

                // Print invalid command then show help
                console.WriteLine(InversionResources.InvalidArguments, commandName);

                p.HelpCommand.ViewHelpForCommand(commandName);
                return 0;
            }
            else
            {
                return command.Execute();
            }
        }
Beispiel #2
0
        public static int Main(string[] args)
        {
            var console = new Inversion.CommandLine.Infrastructure.Console();
            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 (!ArgumentCountValid(command))
            {
                // Get the command name and add it to the argument list of the help command
                string commandName = command.CommandAttribute.CommandName;

                // Print invalid command then show help
                console.WriteLine(InversionResources.InvalidArguments, commandName);

                p.HelpCommand.ViewHelpForCommand(commandName);
                return(0);
            }
            else
            {
                return(command.Execute());
            }
        }