While.CommandLineOptions.CommandLineOptions C# (CSharp) Method

CommandLineOptions() public method

public CommandLineOptions ( string args ) : System
args string
return System
        public CommandLineOptions(string[] args)
        {
            if (args.Length == 0) {
                _empty = true;
                return;
            }
            for (int i = 0; i < args.Length; i++) {
                string arg = args[i];
                string commandArg = null;
                bool wasArg = false;
                if (IsParam(arg, "help", "h", false, out commandArg) || IsParam(arg, "help", "\\?", false, out commandArg)) {
                    _help = true;
                    wasArg = true;
                } else if (IsParam(arg, "debug", "d", false, out commandArg)) {
                    _debug = true;
                    wasArg = true;
                } else if (IsParam(arg, "coursesyntax", "c", false, out commandArg)) {
                    _bookVersion = false;
                    wasArg = true;
                } else if (IsParam(arg, "out", "o", true, out commandArg)) {
                    _outputFile = commandArg;
                    wasArg = true;
                } else if (IsParam(arg, "plugins", "p", true, out commandArg)) {
                    _plugins = new List<string>(commandArg.Split(','));
                    wasArg = true;
                } else {
                    if (i != args.Length - 1) {
                        Console.Error.WriteLine("ERROR: Unknown command line option " + arg);
                        While.Environment.Exit(1);
                    }
                }
                if (i == args.Length - 1 && wasArg && !_help) {
                    Console.Error.WriteLine("ERROR: Missing input file name.");
                    While.Environment.Exit(1);
                }
            }

            _inputFile = args[args.Length - 1];

            if (_inputFile.ToLower() == "stdin") {
                _readStdIn = true;
                if (_outputFile == null) {
                    Console.Error.WriteLine("ERROR: /out:<filename> must be specified when reading source from the standard input stream (STDIN).");
                    While.Environment.Exit(4);
                }
            }
            if (_outputFile == null) {
                _outputFile = Regex.Replace(Path.GetFileName(_inputFile), @"\.w(hile)?$", "");
            }

            if (!_outputFile.ToLower().EndsWith(".exe")) {
                _outputFile += ".exe";
            }
        }