private static int VerifyOutputArgsRun(CLIPackRulesCmdOptions options) { Logger logger = Utils.SetupLogging(options, true); WriteOnce.Log = logger; options.Log = logger; if (options.RepackDefaultRules && !string.IsNullOrEmpty(options.OutputFilePath)) { WriteOnce.Info("output file argument ignored for -d option"); } options.OutputFilePath = options.RepackDefaultRules ? Utils.GetPath(Utils.AppPath.defaultRulesPackedFile) : options.OutputFilePath; if (string.IsNullOrEmpty(options.OutputFilePath)) { WriteOnce.Error(MsgHelp.GetString(MsgHelp.ID.PACK_MISSING_OUTPUT_ARG)); throw new OpException(MsgHelp.GetString(MsgHelp.ID.PACK_MISSING_OUTPUT_ARG)); } else { CommonOutputChecks(options); } return(RunPackRulesCommand(options)); }
/// <summary> /// Responsible for returning the correct cmd and format writer for output of cmd results. An an output /// file will be opened as a stream if provided otherwise the console.out stream is used /// A downcast is expected as the input param containing the common output format and filepath for simplifying /// the allocation to a single method and serves as a type selector but is also recast for command specific /// options in the writer as needed /// </summary> /// <param name="options"></param> /// <returns></returns> public CommandResultsWriter GetWriter(CLICommandOptions options) { return(options switch { CLIAnalyzeCmdOptions cliAnalyzeCmdOptions => GetAnalyzeWriter(cliAnalyzeCmdOptions), CLITagDiffCmdOptions cliTagDiffCmdOptions => GetTagDiffWriter(cliTagDiffCmdOptions), CLIExportTagsCmdOptions cliExportTagsCmdOptions => GetExportTagsWriter(cliExportTagsCmdOptions), CLIVerifyRulesCmdOptions cliVerifyRulesCmdOptions => GetVerifyRulesWriter(cliVerifyRulesCmdOptions), CLIPackRulesCmdOptions cliPackRulesCmdOptions => GetPackRulesWriter(cliPackRulesCmdOptions), _ => throw new OpException($"Unrecognized object type {options.GetType().Name} in writer request") });
private static int VerifyOutputArgsRun(CLIPackRulesCmdOptions options) { loggerFactory = options.GetLoggerFactory(); ILogger logger = loggerFactory.CreateLogger("Program"); if (string.IsNullOrEmpty(options.OutputFilePath)) { logger.LogError(MsgHelp.GetString(MsgHelp.ID.PACK_MISSING_OUTPUT_ARG)); throw new OpException(MsgHelp.GetString(MsgHelp.ID.PACK_MISSING_OUTPUT_ARG)); } else { CommonOutputChecks(options); } return(RunPackRulesCommand(options)); }
private static int RunPackRulesCommand(CLIPackRulesCmdOptions cliOptions) { PackRulesCommand command = new(new PackRulesOptions() { RepackDefaultRules = cliOptions.RepackDefaultRules, CustomRulesPath = cliOptions.CustomRulesPath, ConsoleVerbosityLevel = cliOptions.ConsoleVerbosityLevel, Log = cliOptions.Log, PackEmbeddedRules = cliOptions.PackEmbeddedRules }); PackRulesResult exportTagsResult = command.GetResult(); ResultsWriter.Write(exportTagsResult, cliOptions); return((int)exportTagsResult.ResultCode); }
private static int RunPackRulesCommand(CLIPackRulesCmdOptions cliOptions) { PackRulesCommand command = new(new PackRulesOptions() { CustomRulesPath = cliOptions.CustomRulesPath, CustomCommentsPath = cliOptions.CustomCommentsPath, CustomLanguagesPath = cliOptions.CustomLanguagesPath, PackEmbeddedRules = cliOptions.PackEmbeddedRules }, loggerFactory); PackRulesResult exportTagsResult = command.GetResult(); ResultsWriter writer = new(loggerFactory); writer.Write(exportTagsResult, cliOptions); return((int)exportTagsResult.ResultCode); }
private static int RunPackRulesCommand(CLIPackRulesCmdOptions cliOptions) { PackRulesResult.ExitCode exitCode = PackRulesResult.ExitCode.CriticalError; PackRulesCommand command = new PackRulesCommand(new PackRulesOptions() { RepackDefaultRules = cliOptions.RepackDefaultRules, CustomRulesPath = cliOptions.CustomRulesPath, ConsoleVerbosityLevel = cliOptions.ConsoleVerbosityLevel, Log = cliOptions.Log }); PackRulesResult exportTagsResult = command.GetResult(); exitCode = exportTagsResult.ResultCode; ResultsWriter.Write(exportTagsResult, cliOptions); return((int)exitCode); }
private static CommandResultsWriter GetPackRulesWriter(CLIPackRulesCmdOptions options) { CommandResultsWriter?writer; switch (options.OutputFileFormat.ToLower()) { case "json": writer = new JsonWriter(); break; default: WriteOnce.Error(MsgHelp.FormatString(MsgHelp.ID.CMD_INVALID_ARG_VALUE, "-f")); throw new OpException((MsgHelp.FormatString(MsgHelp.ID.CMD_INVALID_ARG_VALUE, "-f"))); } //assign the stream as a file or console writer.OutputFileName = options.OutputFilePath; writer.TextWriter = GetTextWriter(writer.OutputFileName); return(writer); }