Exemple #1
0
            public bool TryParseArgument(string arg, ICommandLineParser parser)
            {
                if (parser.IsSwitch(arg))
                {
                    var parameter = arg.Substring(1);
                    switch (parameter.ToLowerInvariant())
                    {
                    case "?":
                    case "h":
                    case "help":
                        this.ShowHelp = true;
                        return(true);

                    case "intermediatefolder":
                        this.IntermediateFolder = parser.GetNextArgumentAsDirectoryOrError(arg);
                        return(true);

                    case "o":
                    case "out":
                        this.OutputFile = parser.GetNextArgumentAsFilePathOrError(arg);
                        return(true);

                    case "nologo":
                        this.ShowLogo = false;
                        return(true);

                    case "v":
                    case "verbose":
                        this.Messaging.ShowVerboseMessages = true;
                        return(true);

                    case "sw":
                    case "suppresswarning":
                        var warning = parser.GetNextArgumentOrError(arg);
                        if (!String.IsNullOrEmpty(warning))
                        {
                            var warningNumber = Convert.ToInt32(warning);
                            this.Messaging.SuppressWarningMessage(warningNumber);
                        }
                        return(true);
                    }
                }
                else
                {
                    if (String.IsNullOrEmpty(this.DecompileFilePath))
                    {
                        this.DecompileFilePath = parser.GetArgumentAsFilePathOrError(arg, "decompile file");
                        return(true);
                    }
                    else if (String.IsNullOrEmpty(this.OutputFile))
                    {
                        this.OutputFile = parser.GetArgumentAsFilePathOrError(arg, "output file");
                        return(true);
                    }
                }

                return(false);
            }
Exemple #2
0
        public bool TryParseArgument(ICommandLineParser parser, string argument)
        {
            if (parser.IsSwitch(argument) && argument.Substring(1).Equals("example", StringComparison.OrdinalIgnoreCase))
            {
                this.exampleValueFromCommandLine = parser.GetNextArgumentOrError(argument);
                return(true);
            }

            return(false);
        }
Exemple #3
0
        public bool TryParseArgument(ICommandLineParser parser, string arg)
        {
            if (this.ExtensionArgument == null)
            {
                this.ExtensionArgument = arg;
            }
            else if ('-' == arg[0] || '/' == arg[0])
            {
                string parameter = arg.Substring(1);
                if ("nologo" == parameter)
                {
                    this.ShowLogo = false;
                }
                else if ("o" == parameter || "out" == parameter)
                {
                    this.OutputFile = parser.GetNextArgumentAsFilePathOrError(arg);

                    if (String.IsNullOrEmpty(this.OutputFile))
                    {
                        return(false);
                    }
                }
                else if ("swall" == parameter)
                {
                    this.Messaging.Write(WarningMessages.DeprecatedCommandLineSwitch("swall", "sw"));
                    this.Messaging.SuppressAllWarnings = true;
                }
                else if (parameter.StartsWith("sw"))
                {
                    string paramArg = parameter.Substring(2);
                    try
                    {
                        if (0 == paramArg.Length)
                        {
                            this.Messaging.SuppressAllWarnings = true;
                        }
                        else
                        {
                            int suppressWarning = Convert.ToInt32(paramArg, CultureInfo.InvariantCulture.NumberFormat);
                            if (0 >= suppressWarning)
                            {
                                this.Messaging.Write(ErrorMessages.IllegalSuppressWarningId(paramArg));
                            }

                            this.Messaging.SuppressWarningMessage(suppressWarning);
                        }
                    }
                    catch (FormatException)
                    {
                        this.Messaging.Write(ErrorMessages.IllegalSuppressWarningId(paramArg));
                    }
                    catch (OverflowException)
                    {
                        this.Messaging.Write(ErrorMessages.IllegalSuppressWarningId(paramArg));
                    }
                }
                else if ("wxall" == parameter)
                {
                    this.Messaging.Write(WarningMessages.DeprecatedCommandLineSwitch("wxall", "wx"));
                    this.Messaging.WarningsAsError = true;
                }
                else if (parameter.StartsWith("wx"))
                {
                    string paramArg = parameter.Substring(2);
                    try
                    {
                        if (0 == paramArg.Length)
                        {
                            this.Messaging.WarningsAsError = true;
                        }
                        else
                        {
                            int elevateWarning = Convert.ToInt32(paramArg, CultureInfo.InvariantCulture.NumberFormat);
                            if (0 >= elevateWarning)
                            {
                                this.Messaging.Write(ErrorMessages.IllegalWarningIdAsError(paramArg));
                            }

                            this.Messaging.ElevateWarningMessage(elevateWarning);
                        }
                    }
                    catch (FormatException)
                    {
                        this.Messaging.Write(ErrorMessages.IllegalWarningIdAsError(paramArg));
                    }
                    catch (OverflowException)
                    {
                        this.Messaging.Write(ErrorMessages.IllegalWarningIdAsError(paramArg));
                    }
                }
                else if ("v" == parameter)
                {
                    this.Messaging.ShowVerboseMessages = true;
                }
                else if ("indent" == parameter)
                {
                    try
                    {
                        this.Indent = Int32.Parse(parser.GetNextArgumentOrError(arg), CultureInfo.InvariantCulture);
                    }
                    catch
                    {
                        throw new ArgumentException("Invalid numeric argument.", parameter);
                    }
                }
            }

            this.ExtensionOptions.Add(arg);
            return(true);
        }
Exemple #4
0
            public bool TryParseArgument(string arg, ICommandLineParser parser)
            {
                if (parser.IsSwitch(arg))
                {
                    var parameter = arg.Substring(1).ToLowerInvariant();
                    switch (parameter)
                    {
                    case "?":
                    case "h":
                    case "help":
                        this.ShowHelp = true;
                        return(true);

                    case "arch":
                    case "platform":
                    {
                        var value = parser.GetNextArgumentOrError(arg);
                        if (Enum.TryParse(value, true, out Platform platform))
                        {
                            this.Platform = platform;
                            return(true);
                        }
                        break;
                    }

                    case "bf":
                    case "bindfiles":
                        this.BindFiles = true;
                        return(true);

                    case "bindpath":
                    {
                        var value = parser.GetNextArgumentOrError(arg);
                        if (value != null && this.TryParseBindPath(value, out var bindPath))
                        {
                            this.BindPaths.Add(bindPath);
                            return(true);
                        }
                        return(false);
                    }

                    case "cc":
                        this.CabCachePath = parser.GetNextArgumentOrError(arg);
                        return(true);

                    case "culture":
                        parser.GetNextArgumentOrError(arg, this.Cultures);
                        return(true);

                    case "contentsfile":
                        this.ContentsFile = parser.GetNextArgumentAsFilePathOrError(arg);
                        return(true);

                    case "outputsfile":
                        this.OutputsFile = parser.GetNextArgumentAsFilePathOrError(arg);
                        return(true);

                    case "builtoutputsfile":
                        this.BuiltOutputsFile = parser.GetNextArgumentAsFilePathOrError(arg);
                        return(true);

                    case "d":
                    case "define":
                        parser.GetNextArgumentOrError(arg, this.Defines);
                        return(true);

                    case "dcl":
                    case "defaultcompressionlevel":
                    {
                        var value = parser.GetNextArgumentOrError(arg);
                        if (Enum.TryParse(value, true, out CompressionLevel compressionLevel))
                        {
                            this.DefaultCompressionLevel = compressionLevel;
                            return(true);
                        }
                        return(false);
                    }

                    case "i":
                    case "includepath":
                        parser.GetNextArgumentOrError(arg, this.IncludeSearchPaths);
                        return(true);

                    case "intermediatefolder":
                        this.IntermediateFolder = parser.GetNextArgumentAsDirectoryOrError(arg);
                        return(true);

                    case "loc":
                        parser.GetNextArgumentAsFilePathOrError(arg, "localization files", this.LocalizationFilePaths);
                        return(true);

                    case "lib":
                        parser.GetNextArgumentAsFilePathOrError(arg, "library files", this.LibraryFilePaths);
                        return(true);

                    case "o":
                    case "out":
                        this.OutputFile = parser.GetNextArgumentAsFilePathOrError(arg);
                        return(true);

                    case "outputtype":
                        this.OutputType = parser.GetNextArgumentOrError(arg);
                        return(true);

                    case "pdb":
                        this.PdbFile = parser.GetNextArgumentAsFilePathOrError(arg);
                        return(true);

                    case "pdbtype":
                    {
                        var value = parser.GetNextArgumentOrError(arg);
                        if (Enum.TryParse(value, true, out PdbType pdbType))
                        {
                            this.PdbType = pdbType;
                            return(true);
                        }
                        return(false);
                    }

                    case "nologo":
                        this.ShowLogo = false;
                        return(true);

                    case "v":
                    case "verbose":
                        this.Messaging.ShowVerboseMessages = true;
                        return(true);

                    case "sval":
                        // todo: implement
                        return(true);
                    }

                    if (parameter.StartsWith("sw"))
                    {
                        this.ParseSuppressWarning(parameter, "sw".Length, parser);
                        return(true);
                    }
                    else if (parameter.StartsWith("suppresswarning"))
                    {
                        this.ParseSuppressWarning(parameter, "suppresswarning".Length, parser);
                        return(true);
                    }
                    else if (parameter.StartsWith("wx"))
                    {
                        this.ParseWarningAsError(parameter, "wx".Length, parser);
                        return(true);
                    }

                    return(false);
                }
                else
                {
                    parser.GetArgumentAsFilePathOrError(arg, "source code", this.SourceFilePaths);
                    return(true);
                }
            }
Exemple #5
0
            public bool TryParseArgument(string arg, ICommandLineParser parser)
            {
                if (parser.IsSwitch(arg))
                {
                    var parameter = arg.Substring(1);
                    switch (parameter.ToLowerInvariant())
                    {
                    case "?":
                    case "h":
                    case "help":
                        this.ShowHelp = true;
                        return(true);

                    case "arch":
                    case "platform":
                    {
                        var value = parser.GetNextArgumentOrError(arg);
                        if (Enum.TryParse(value, true, out Platform platform))
                        {
                            this.Platform = platform;
                            return(true);
                        }
                        break;
                    }

                    case "bindfiles":
                        this.BindFiles = true;
                        return(true);

                    case "bindpath":
                    {
                        var value = parser.GetNextArgumentOrError(arg);
                        if (this.TryParseBindPath(value, out var bindPath))
                        {
                            this.BindPaths.Add(bindPath);
                            return(true);
                        }
                        break;
                    }

                    case "cc":
                        this.CabCachePath = parser.GetNextArgumentOrError(arg);
                        return(true);

                    case "culture":
                        parser.GetNextArgumentOrError(arg, this.Cultures);
                        return(true);

                    case "contentsfile":
                        this.ContentsFile = parser.GetNextArgumentAsFilePathOrError(arg);
                        return(true);

                    case "outputsfile":
                        this.OutputsFile = parser.GetNextArgumentAsFilePathOrError(arg);
                        return(true);

                    case "builtoutputsfile":
                        this.BuiltOutputsFile = parser.GetNextArgumentAsFilePathOrError(arg);
                        return(true);

                    case "d":
                    case "define":
                        parser.GetNextArgumentOrError(arg, this.Defines);
                        return(true);

                    case "i":
                    case "includepath":
                        parser.GetNextArgumentOrError(arg, this.IncludeSearchPaths);
                        return(true);

                    case "intermediatefolder":
                        this.IntermediateFolder = parser.GetNextArgumentAsDirectoryOrError(arg);
                        return(true);

                    case "loc":
                        parser.GetNextArgumentAsFilePathOrError(arg, "localization files", this.LocalizationFilePaths);
                        return(true);

                    case "lib":
                        parser.GetNextArgumentAsFilePathOrError(arg, "library files", this.LibraryFilePaths);
                        return(true);

                    case "o":
                    case "out":
                        this.OutputFile = parser.GetNextArgumentAsFilePathOrError(arg);
                        return(true);

                    case "outputtype":
                        this.OutputType = parser.GetNextArgumentOrError(arg);
                        return(true);

                    case "nologo":
                        this.ShowLogo = false;
                        return(true);

                    case "v":
                    case "verbose":
                        this.Messaging.ShowVerboseMessages = true;
                        return(true);

                    case "sval":
                        // todo: implement
                        return(true);

                    case "sw":
                    case "suppresswarning":
                        var warning = parser.GetNextArgumentOrError(arg);
                        if (!String.IsNullOrEmpty(warning))
                        {
                            var warningNumber = Convert.ToInt32(warning);
                            this.Messaging.SuppressWarningMessage(warningNumber);
                        }
                        return(true);
                    }

                    return(false);
                }
                else
                {
                    parser.GetArgumentAsFilePathOrError(arg, "source code", this.SourceFilePaths);
                    return(true);
                }
            }
        public bool TryParseArgument(ICommandLineParser parser, string argument)
        {
            if (!parser.IsSwitch(argument))
            {
                this.SearchPatterns.Add(argument);
                return(true);
            }

            var parameter = argument.Substring(1);

            switch (parameter.ToLowerInvariant())
            {
            case "?":
            case "h":
            case "-help":
                this.ShowHelp    = true;
                this.ShowLogo    = true;
                this.StopParsing = true;
                return(true);

            case "-custom-table":
                var customTableSetting = parser.GetNextArgumentOrError(argument);
                switch (customTableSetting)
                {
                case "bundle":
                    this.CustomTableSetting = CustomTableTarget.Bundle;
                    break;

                case "msi":
                    this.CustomTableSetting = CustomTableTarget.Msi;
                    break;

                default:
                    parser.ReportErrorArgument(argument);
                    break;
                }
                return(true);

            case "n":
            case "-dry-run":
                this.DryRun = true;
                return(true);

            case "nologo":
            case "-nologo":
                this.ShowLogo = false;
                return(true);

            case "s":
            case "r":
            case "-recurse":
            case "-recursive":
                this.Recurse = true;
                return(true);

            default:     // other parameters
                if (parameter.StartsWith("set1", StringComparison.Ordinal))
                {
                    this.SettingsFile1 = parameter.Substring(4);
                    return(true);
                }
                else if (parameter.StartsWith("set2", StringComparison.Ordinal))
                {
                    this.SettingsFile2 = parameter.Substring(4);
                    return(true);
                }
                else if (parameter.StartsWith("indent:", StringComparison.Ordinal))
                {
                    try
                    {
                        this.IndentationAmount = Convert.ToInt32(parameter.Substring(7));
                    }
                    catch
                    {
                        parser.ReportErrorArgument(parameter);     //  $"Invalid numeric argument: {parameter}";
                    }
                    return(true);
                }

                return(false);
            }
        }