Esempio n. 1
0
        public static int Main(string[] args)
        {
            // Launch debugger if the "--debugger" flag is present in the command line arguments.
            // We want to do this as early as possible so just check the flag manually, rather than doing the
            // more robust argument parsing.
            if (args.Any(i => i == "--debugger"))
            {
                Debugger.Launch();
            }

            if (args.Length == 1 && args.Any(i => i == "--verbose" || i == "--debug"))
            {
                // Start the gui with logging enabled #437
                var guiCommand = args.ToList();
                guiCommand.Insert(0, "gui");
                args = guiCommand.ToArray();
            }

            Logging.Initialize();
            log.Info("CKAN started.");

            // If we're starting with no options then invoke the GUI instead.
            if (args.Length == 0)
            {
                return(Gui(new GuiOptions(), args));
            }

            // We shouldn't instantiate Options if it's a subcommand.
            // It breaks command-specific help, for starters.
            try
            {
                switch (args[0])
                {
                case "repair":
                    var repair = new Repair();
                    return(repair.RunSubCommand(new SubCommandOptions(args)));

                case "ksp":
                    var ksp = new KSP();
                    return(ksp.RunSubCommand(new SubCommandOptions(args)));

                case "compat":
                    var compat = new CompatSubCommand();
                    return(compat.RunSubCommand(new SubCommandOptions(args)));

                case "repo":
                    var repo = new Repo();
                    return(repo.RunSubCommand(new SubCommandOptions(args)));
                }
            }
            catch (NoGameInstanceKraken)
            {
                return(printMissingInstanceError(new ConsoleUser(false)));
            }
            finally
            {
                log.Info("CKAN exiting.");
            }

            Options cmdline;

            try
            {
                cmdline = new Options(args);
            }
            catch (BadCommandKraken)
            {
                return(AfterHelp());
            }
            finally
            {
                log.Info("CKAN exiting.");
            }

            // Process commandline options.
            CommonOptions options = (CommonOptions)cmdline.options;
            IUser         user    = new ConsoleUser(options.Headless);
            KSPManager    manager = new KSPManager(user);

            try
            {
                int exitCode = options.Handle(manager, user);
                if (exitCode != Exit.OK)
                {
                    return(exitCode);
                }
                // Don't bother with instances or registries yet because some commands don't need them.
                return(RunSimpleAction(cmdline, options, args, user, manager));
            }
            finally
            {
                log.Info("CKAN exiting.");
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Run whatever action the user has provided
        /// </summary>
        /// <returns>The exit status that should be returned to the system.</returns>
        private static int RunAction(Options cmdline, CommonOptions options, string[] args, IUser user, KSPManager manager)
        {
            switch (cmdline.action)
            {
            case "gui":
                return(Gui((GuiOptions)options, args));

            case "version":
                return(Version(user));

            case "update":
                return((new Update(user)).RunCommand(manager.CurrentInstance, (UpdateOptions)cmdline.options));

            case "available":
                return((new Available(user)).RunCommand(manager.CurrentInstance, (AvailableOptions)cmdline.options));

            //return Available(manager.CurrentInstance, user);

            case "install":
                Scan(manager.CurrentInstance, user, cmdline.action);
                return((new Install(user)).RunCommand(manager.CurrentInstance, (InstallOptions)cmdline.options));

            case "scan":
                return(Scan(manager.CurrentInstance, user));

            case "list":
                return((new List(user)).RunCommand(manager.CurrentInstance, (ListOptions)cmdline.options));

            case "show":
                return((new Show(user)).RunCommand(manager.CurrentInstance, (ShowOptions)cmdline.options));

            case "search":
                return((new Search(user)).RunCommand(manager.CurrentInstance, options));

            case "remove":
                return((new Remove(user)).RunCommand(manager.CurrentInstance, cmdline.options));

            case "upgrade":
                Scan(manager.CurrentInstance, user, cmdline.action);
                return((new Upgrade(user)).RunCommand(manager.CurrentInstance, cmdline.options));

            case "clean":
                return(Clean(manager.CurrentInstance));

            case "repair":
                var repair = new Repair(manager.CurrentInstance, user);
                return(repair.RunSubCommand((SubCommandOptions)cmdline.options));

            case "ksp":
                var ksp = new KSP(manager, user);
                return(ksp.RunSubCommand((SubCommandOptions)cmdline.options));

            case "compat":
                var compat = new CompatSubCommand(manager, user);
                return(compat.RunSubCommand((SubCommandOptions)cmdline.options));

            case "repo":
                var repo = new Repo(manager, user);
                return(repo.RunSubCommand((SubCommandOptions)cmdline.options));

            case "compare":
                return((new Compare(user)).RunCommand(manager.CurrentInstance, cmdline.options));

            default:
                user.RaiseMessage("Unknown command, try --help");
                return(Exit.BADOPT);
            }
        }