コード例 #1
0
        public static void Main(string[] args)
        {
            var sink      = new ConsoleSink();
            var chooser   = new ConsoleChooser();
            var envParams = new EnvParams();

            using (var ci = new CommandInterface(sink, chooser, envParams))
            {
                Console.CancelKeyPress += (x, y) =>
                {
                    y.Cancel = true;
                    ci.Cancel();
                };

                //// If errors occured while parsing switches
                //// then treat this an exit condition.
                bool isExit;
                ci.DoOptions(out isExit);
                if (isExit || sink.PrintedError)
                {
                    Environment.ExitCode = sink.PrintedError ? 1 : 0;
                    return;
                }

                string line;
                while (true)
                {
                    //// Because pressing CTRL-C may return a null line
                    line = Console.ReadLine();
                    line = line == null ? string.Empty : line.Trim();
                    if (line == CommandInterface.ExitCommand ||
                        line == CommandInterface.ExitShortCommand)
                    {
                        Environment.ExitCode = sink.PrintedError ? 1 : 0;
                        return;
                    }

                    ci.DoCommand(line);
                }
            }
        }