public void Parse() { ExpectedLexeme expectedLexeme = ExpectedLexeme.Option; accepted = false; for (int i = 1; i < Environment.GetCommandLineArgs().GetLength(0); i++) { string arg = Environment.GetCommandLineArgs()[i]; if (expectedLexeme == ExpectedLexeme.Option) { accepted = false; if (arg.Equals("-i")) { expectedLexeme = ExpectedLexeme.FileName; } else if (arg.Equals("-wl")) { expectedLexeme = ExpectedLexeme.WarningLevel; } else { Console.WriteLine("Unknown option: {0}", arg); } } else { accepted = true; switch (expectedLexeme) { case ExpectedLexeme.FileName: fileName = Environment.ExpandEnvironmentVariables(arg); break; case ExpectedLexeme.WarningLevel: int level; bool parsed = int.TryParse(arg, out level); if (!parsed || level < (int)WarningLevel.Low || level > (int)WarningLevel.High) { accepted = false; Console.WriteLine("Invalid warning level value: {0}", arg); return; } else { minWarningLevel = (WarningLevel)level; } break; default: accepted = false; break; } expectedLexeme = ExpectedLexeme.Option; } } }
public void Parse() { if (Environment.GetCommandLineArgs().GetLength(0) > 1) { switch (Environment.GetCommandLineArgs()[1].ToLower()) { case "extract": Mode = CommandMode.ModeExtract; break; default: Console.WriteLine("Command was not specified"); Console.WriteLine("Assembly/exe file name is not specified"); return; } } else { return; } ExpectedLexeme expectedLexeme = ExpectedLexeme.None; Accepted = true; for (int i = 2; i < Environment.GetCommandLineArgs().GetLength(0); i++) { string arg = Environment.GetCommandLineArgs()[i]; if (expectedLexeme == ExpectedLexeme.None) { if (arg.Equals("--assembly", StringComparison.InvariantCultureIgnoreCase)) { expectedLexeme = ExpectedLexeme.AssemblyName; } else { Accepted = false; Console.WriteLine("Unknown option: {0}", arg); } } else { switch (expectedLexeme) { case ExpectedLexeme.AssemblyName: AssemblyName = Path.GetFullPath(Environment.ExpandEnvironmentVariables(arg)); break; default: Accepted = false; break; } expectedLexeme = ExpectedLexeme.None; } } }