public static CommandResultsWriter GetExportWriter(CLIExportTagsCmdOptions options) { CommandResultsWriter?writer; switch (options.OutputFileFormat.ToLower()) { case "_dummy": writer = new ExportDummyWriter(); break; case "json": writer = new JsonWriter(); break; case "text": writer = new ExportTextWriter(); 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); }
private static int VerifyOutputArgsRun(CLIExportTagsCmdOptions options) { loggerFactory = options.GetLoggerFactory(); CommonOutputChecks(options); return(RunExportTagsCommand(options)); }
private static int VerifyOutputArgsRun(CLIExportTagsCmdOptions options) { Logger logger = Utils.SetupLogging(options, true); WriteOnce.Log = logger; options.Log = logger; CommonOutputChecks(options); return(RunExportTagsCommand(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 RunExportTagsCommand(CLIExportTagsCmdOptions cliOptions) { ExportTagsCommand command = new(new ExportTagsOptions() { IgnoreDefaultRules = cliOptions.IgnoreDefaultRules, CustomRulesPath = cliOptions.CustomRulesPath, }, loggerFactory); ExportTagsResult exportTagsResult = command.GetResult(); ResultsWriter writer = new(loggerFactory); writer.Write(exportTagsResult, cliOptions); return((int)exportTagsResult.ResultCode); }
private static int RunExportTagsCommand(CLIExportTagsCmdOptions cliOptions) { ExportTagsCommand command = new(new ExportTagsOptions() { IgnoreDefaultRules = cliOptions.IgnoreDefaultRules, CustomRulesPath = cliOptions.CustomRulesPath, ConsoleVerbosityLevel = cliOptions.ConsoleVerbosityLevel, Log = cliOptions.Log }); ExportTagsResult exportTagsResult = command.GetResult(); ResultsWriter.Write(exportTagsResult, cliOptions); return((int)exportTagsResult.ResultCode); }