Пример #1
0
        private bool TryParseArg(List <string> args, out GenArgs result, out string errMsg)
        {
            var helpWriter = new StringWriter();
            var parser     = new Parser(ps =>
            {
                ps.HelpWriter = helpWriter;
            });;
            var parseResult = parser.ParseArguments <GenArgs>(args);

            if (parseResult.Tag == ParserResultType.NotParsed)
            {
                errMsg = helpWriter.ToString();
                result = null;
                return(false);
            }
            else
            {
                result = (parseResult as Parsed <GenArgs>).Value;
                errMsg = null;

                string inputDataDir  = result.InputDataDir;
                string outputCodeDir = result.OutputCodeDir;
                string outputDataDir = result.OutputDataDir;

                var genTypes = result.GenType.Split(',').Select(s => s.Trim()).ToList();

                if (genTypes.Any(t => t.StartsWith("code_", StringComparison.Ordinal)) && string.IsNullOrWhiteSpace(outputCodeDir))
                {
                    errMsg = "--outputcodedir missing";
                    return(false);
                }
                else if (genTypes.Any(t => t.StartsWith("data_", StringComparison.Ordinal)))
                {
                    if (string.IsNullOrWhiteSpace(inputDataDir))
                    {
                        errMsg = "--inputdatadir missing";
                        return(false);
                    }
                    if (string.IsNullOrWhiteSpace(outputDataDir))
                    {
                        errMsg = "--outputdatadir missing";
                        return(false);
                    }
                }

                return(true);
            }
        }
Пример #2
0
        private static bool TryParseArg(List <string> args, out GenArgs options, out string errMsg)
        {
            var helpWriter = new StringWriter();
            var parser     = new Parser(ps =>
            {
                ps.HelpWriter = helpWriter;
            });;
            var parseResult = parser.ParseArguments <GenArgs>(args);

            if (parseResult.Tag == ParserResultType.NotParsed)
            {
                errMsg  = helpWriter.ToString();
                options = null;
                return(false);
            }
            else
            {
                options = (parseResult as Parsed <GenArgs>).Value;
                errMsg  = null;

                string inputDataDir  = options.InputDataDir;
                string outputCodeDir = options.OutputCodeDir;
                string outputDataDir = options.OutputDataDir;

                var genTypes = options.GenType.Split(',').Select(s => s.Trim()).ToList();

                if (genTypes.Any(t => t.StartsWith("code_", StringComparison.Ordinal)) && string.IsNullOrWhiteSpace(outputCodeDir))
                {
                    errMsg = "--outputcodedir missing";
                    return(false);
                }
                if (genTypes.Any(t => t.StartsWith("data_", StringComparison.Ordinal)))
                {
                    if (string.IsNullOrWhiteSpace(inputDataDir))
                    {
                        errMsg = "--inputdatadir missing";
                        return(false);
                    }
                    if (string.IsNullOrWhiteSpace(outputDataDir))
                    {
                        errMsg = "--outputdatadir missing";
                        return(false);
                    }
                    if (genTypes.Contains("data_resources") && string.IsNullOrWhiteSpace(options.OutputDataResourceListFile))
                    {
                        errMsg = "--output_data_resource_list_file missing";
                        return(false);
                    }
                    if (genTypes.Contains("output_data_json_monolithic_file") && string.IsNullOrWhiteSpace(options.OutputDataJsonMonolithicFile))
                    {
                        errMsg = "--output_data_json_monolithic_file missing";
                        return(false);
                    }

                    if (string.IsNullOrWhiteSpace(options.L10nInputTextTableFiles) ^ string.IsNullOrWhiteSpace(options.L10nOutputNotTranslatedTextFile))
                    {
                        errMsg = "--input_l10n_text_files must be provided with --output_l10n_not_translated_text_file";
                        return(false);
                    }
                    if (genTypes.Contains("data_template") ^ !string.IsNullOrWhiteSpace(options.TemplateDataFile))
                    {
                        errMsg = "gen_types data_template should use with --template:data:file";
                        return(false);
                    }
                    if (genTypes.Contains("convert_template") ^ !string.IsNullOrWhiteSpace(options.TemplateConvertFile))
                    {
                        errMsg = "gen_types convert_template should use with --template:convert:file";
                        return(false);
                    }
                    if (genTypes.Contains("code_template") ^ !string.IsNullOrWhiteSpace(options.TemplateCodeDir))
                    {
                        errMsg = "gen_types code_template should use with --template:code:dir";
                        return(false);
                    }
                }

                if (string.IsNullOrWhiteSpace(options.L10nPatchName) ^ string.IsNullOrWhiteSpace(options.L10nPatchInputDataDir))
                {
                    errMsg = "--patch must be provided with --patch_input_data_dir";
                    return(false);
                }

                if (options.GenType.Contains("typescript_bin") && !options.ValidateTypescriptRequire(options.GenType, ref errMsg))
                {
                    return(false);
                }
                if (options.GenType.Contains("go_") && !options.ValidateGoRequire(options.GenType, ref errMsg))
                {
                    return(false);
                }
                if (!options.ValidateConvention(ref errMsg))
                {
                    return(false);
                }

                return(true);
            }
        }