public ColorfulStdOut( [NotNull] IStdOut stdOut, [NotNull] IColorTheme colorTheme) { _stdOut = stdOut ?? throw new ArgumentNullException(nameof(stdOut)); _colorTheme = colorTheme ?? throw new ArgumentNullException(nameof(colorTheme)); }
// ******************************************************************************** /// <summary> /// Display the help text on the console. /// </summary> /// <param name="console">Console used for writing.</param> /// <param name="data">The help data for rendering.</param> /// <created>GJK,23/10/2020</created> /// <changed>GJK,23/10/2020</changed> // ******************************************************************************** public static void Show(this IStdOut console, HelpData data) { if (data == null) { throw new ArgumentNullException(nameof(data), "Expect helpdata to display."); } int longestKeyLenght = 5; foreach (var item in data.Parameters) { if (item.Key.Length > longestKeyLenght) { longestKeyLenght = item.Key.Length + 2; } } console?.WriteLine("Help:"); if (!string.IsNullOrEmpty(data.Description)) { console?.WriteLine(data.Description); } console?.WriteLine("Key{0}Description", GetSpaces(longestKeyLenght - 3)); foreach (var item in data.Parameters) { console.WriteLine("{0}{1}{2}", item.Key, GetSpaces(longestKeyLenght - item.Key.Length), item.Description); } console?.WriteLine("Arguments are parsed as"); console?.WriteLine("Key:Value"); }
public CmdArgConfiguratorTests() { _config = new CmdArgConfiguration { OnUnrecognizedArguments = default(Action <List <string> >), ShowHelpOnExtraArguments = true, CustomHelp = default(Action <IStdOut, HelpData>) }; _console = new Mock <IStdOut>().Object; _testClass = new CmdArgConfigurator(_config, _console); }
// ******************************************************************************** /// <summary> /// Create a new Command Argument Configurator class. /// </summary> /// <param name="console">The output console</param> /// <param name="config">The parameter configuration</param> /// <returns>CmdArgConfiguration</returns> /// <created>GJK,23/10/2020</created> /// <changed>GJK,23/10/2020</changed> // ******************************************************************************** public CmdArgConfigurator(CmdArgConfiguration config, IStdOut console) { if (config == null) { throw new ArgumentNullException(nameof(config), "Configuration is required."); } _config = config; Console = console; }
/// <summary>Registers an intent to use the LeanTest attribute on test methods.</summary> /// <remarks>This causes LeanTest scenario IDs and tags as well as MsTest descriptions to be written to the test log (.trx-file).</remarks> public static ContextBuilder RegisterAttributes(this ContextBuilder theContextBuilder, string testName, Assembly assembly = null) { assembly ??= Assembly.GetCallingAssembly(); IStdOut stdOut = DefaultStdOut; return(theContextBuilder .RegisterDescription(testName, assembly, null, stdOut) .RegisterScenarioId(testName, assembly, null, stdOut) .RegisterTags(testName, assembly, null, stdOut)); }
public BuildLogFlow( [NotNull] ILog <BuildLogFlow> log, [NotNull, Tag(Tags.Base)] IStdOut stdOut, [NotNull] Func <int, IBuildLogFlow> flowFactory, int tabs) { _log = log ?? throw new ArgumentNullException(nameof(log)); _stdOut = stdOut ?? throw new ArgumentNullException(nameof(stdOut)); _flowFactory = flowFactory ?? throw new ArgumentNullException(nameof(flowFactory)); _tabs = tabs; }
/// <summary>Registers an intent to use the <c>Description</c> attribute on test methods.</summary> /// <remarks>This causes MsTest descriptions to be written to the test log (.trx-file).</remarks> public static ContextBuilder RegisterDescription(this ContextBuilder theContextBuilder, string testName, Assembly assembly = null, Type extraType = null, IStdOut stdOut = null) { assembly ??= Assembly.GetCallingAssembly(); stdOut ??= DefaultStdOut; Type[] types = BothTypes(extraType, typeof(TestDescriptionAttribute)); MethodInfo[] allMethodsForTest = GetMethodsForTest(testName, assembly); foreach (Type type in types) { foreach (MethodInfo methodInfo in allMethodsForTest) { foreach (IAttributeValue attribute in methodInfo.GetCustomAttributes(type, false)) { stdOut.WriteLine($@"{TestDescriptionAttribute.Prefix}{attribute.Value}{TestDescriptionAttribute.Postfix}"); } } } return(theContextBuilder); }
/// <summary>Registers an intent to use the <c>Description</c> attribute on test methods.</summary> /// <remarks>This causes MsTest descriptions to be written to the test log (.trx-file).</remarks> public static ContextBuilder RegisterDescription(this ContextBuilder theContextBuilder, TestContext testContext, Assembly assembly = null, IStdOut stdOut = null) => theContextBuilder.RegisterDescription(testContext.MethodName, assembly ?? Assembly.GetCallingAssembly(), typeof(TestDescriptionAttribute), stdOut ?? new StdOutTestOutputHelper(testContext));
// ******************************************************************************** /// <summary> /// Parse and handle the arguments. /// </summary> /// <param name="configAction">The command line parameter configuration.</param> /// <param name="stdOut">Output channel (default null)</param> /// <param name="args">arguments</param> /// <returns>A list with unrecognized command line arguments.</returns> /// <created>GJK,23/10/2020</created> /// <changed>GJK,23/10/2020</changed> // ******************************************************************************** public static List <string> ParseArgs(Action <CmdArgConfigurator> configAction, IStdOut stdOut = null, params string[] args) { if (configAction == null) { throw new ArgumentNullException(nameof(configAction), "Expected a method for configurating the command arguments."); } var config = new CmdArgConfiguration(); var configurator = new CmdArgConfigurator(config); try { configAction(configurator); } catch (Exception e) { throw new ArgumentException("Exception thrown in config action passed to CmdArgParser.Parse method. See inner exception for more details", e); } var extraArgs = new List <string>(); if (args.Length > 0) { foreach (var argument in args) { var argumentLC = argument.ToLower(); var argParsed = false; foreach (var parameter in config.Parameters) { foreach (var key in parameter.Keys) { if (argumentLC.StartsWith(key)) { var rightSide = argument.Substring(key.Length); if (string.IsNullOrEmpty(rightSide)) { parameter.Handler(string.Empty); argParsed = true; } else if (rightSide.StartsWith(":")) { var value = rightSide.Substring(1); parameter.Handler(value); argParsed = true; } } } } if (!argParsed) { extraArgs.Add(argument); } } } if (extraArgs.Count > 0 && config.ShowHelpOnExtraArguments) { stdOut?.WriteLine("Unrecognized arguments: "); foreach (var extraArg in extraArgs) { stdOut?.WriteLine("Key: {0}", extraArg); } } return(extraArgs); }
// ******************************************************************************** /// <summary> /// Parse and handle the command line arguments. /// </summary> /// <param name="configAction"></param> /// <param name="stdOut"></param> /// <returns></returns> /// <created>GJK,23/10/2020</created> /// <changed>GJK,23/10/2020</changed> // ******************************************************************************** public static List <string> ParseCommandLineArgs(Action <CmdArgConfigurator> configAction, IStdOut stdOut = null) { var args = Environment.GetCommandLineArgs(); if (args.Length > 0) { args = args.Skip(1).ToArray(); } ; return(ParseArgs(configAction, stdOut, args)); }