public void ListAllowed( [Flag("List", 'l', "Lists the names that are in the allowed list.")] bool list) { if (Options.Instance.Allowed != null && Options.Instance.Allowed.Count > 0) { foreach (var s in Options.Instance.Allowed) { if (Debug.RegisteredClasses.ContainsKey(s)) { ConsoleBase.WriteCommandResponse(Debug.RegisteredClasses[s], "[{0}]\r\n", s); } else { ConsoleBase.WriteCommandResponse(ConsoleBase.Colors.Progress, "[{0}]\r\n", s); } } } else { ConsoleBase.WriteCommandResponse(ConsoleBase.Colors.Progress, "There are no names in the allowed list.\r\n"); } }
public void SetChrome( [Flag("Basic", 'b', "Selects the basic chrome option.", true)] bool basic, [Flag("Round", 'r', "Selects the round chrome option.", true)] bool round, [Flag("Thick", 't', "Specifies to use thick headers when possible.", true)] bool thick, [Flag("Square", 's', "Selects the square chrome option.", true)] bool square) { if (basic || round || square) { if (round) { Formatters.Chrome = new RoundedChrome(thick); } else if (square) { Formatters.Chrome = new SquareChrome(thick); } else { Formatters.Chrome = new BasicChrome(); } } ConsoleBase.WriteCommandResponse(ConsoleBase.Colors.Progress, "The current selected chrome is: '{0}'.", Formatters.Chrome.GetType().FullName); var rnd = Formatters.Chrome as RoundedChrome; if (rnd != null) { ConsoleBase.WriteCommandResponse(ConsoleBase.Colors.Progress, "{1}Using thick headers: '{0}'.", rnd.ThickHeaders, ConsoleBase.NewLine); } else { var sqr = Formatters.Chrome as SquareChrome; if (sqr != null) { ConsoleBase.WriteCommandResponse(ConsoleBase.Colors.Progress, "{1}Using thick headers: '{0}'.", sqr.ThickHeaders, ConsoleBase.NewLine); } } }
/// <summary> /// Prints the current logging configuration to the console. /// </summary> private void PrintCurrentConfiguration() { var dis = "Disabled"; var ena = "Enabled"; var table = Table.Create() .AddRow("Debug Messages", Options.Instance.LogLevels.Contains(LogLevels.Debug) ? ena : dis) .AddRow("Notices", Options.Instance.LogLevels.Contains(LogLevels.Notice) ? ena : dis) .AddRow("Warnings", Options.Instance.LogLevels.Contains(LogLevels.Warning) ? ena : dis) .AddRow("Errors", Options.Instance.LogLevels.Contains(LogLevels.Error) ? ena : dis) .AddRow("Exceptions", Options.Instance.LogLevels.Contains(LogLevels.Exception) ? ena : dis) .ForEachCellInColumn(1, c => c.Color = c.Contents == ena ? ConsoleBase.Colors.BrightGreen : ConsoleBase.Colors.BrightRed) .FormatColumn(0, HorizontalAlignment.Right) .FormatColumn(1, HorizontalAlignment.Left); table.Columns[0][0].Color = ConsoleBase.Colors.Debug; table.Columns[0][1].Color = ConsoleBase.Colors.Notice; table.Columns[0][2].Color = ConsoleBase.Colors.Warning; table.Columns[0][3].Color = ConsoleBase.Colors.Error; table.Columns[0][4].Color = ConsoleBase.Colors.Exception; ConsoleBase.WriteCommandResponse(table.ToString()); }
/// <summary> /// Initializes a new instance of the <see cref="GlobalCommand"/> class. /// </summary> /// <param name="name">The name of the command, as it should appear in the processor console. Limited to 23 characters.</param> /// <param name="help">Help text shown when entering 'help user' on a processor command prompt. Limited to 79 characters.</param> /// <param name="access">The user access level the command should be given.</param> public GlobalCommand(string name, string help, Access access) { if (name.Length >= 23) { throw new ArgumentOutOfRangeException("name", "The name can be no longer than 23 characters."); } Name = name; Help = help.Substring(0, Math.Min(help.Length, 76)); if (Help.Length == 76) { Help = Help + "..."; } CommandAccess = access; WriteErrorMethod = (msg) => ConsoleBase.WriteCommandResponse(ConsoleBase.Colors.BrightRed, msg); WriteHelpMethod = (msg) => ConsoleBase.WriteCommandResponse(ConsoleBase.Colors.BrightYellow, msg); FormatHelpCommandMethod = (msg) => ConsoleBase.Colors.BrightGreen.FormatText(msg); FormatHelpVerbMethod = (msg) => ConsoleBase.Colors.BrightMagenta.FormatText(msg); FormatHelpOperandMethod = (msg) => ConsoleBase.Colors.BrightCyan.FormatText(msg); FormatHelpFlagMethod = (msg) => ConsoleBase.Colors.BrightBlue.FormatText(msg); FormatHelpSampleMethod = (msg) => ConsoleBase.Colors.BrightGreen.FormatText(msg); FormatHelpTextMethod = (msg) => ConsoleBase.Colors.BrightYellow.FormatText(msg); }
public void EchoMessage( [Operand("message", "The message to echo.")] string message, [Flag("caps", 'c', "When present prints the message in all caps.", true)] bool caps) { ConsoleBase.WriteCommandResponse(caps ? message.ToUpper() : message); }
public void ToggleLevels( [Flag("debug", 'd', "Include to enable printing debug messages. Exclude to disable.", true)] bool debug, [Flag("progress", 'p', "Include to enable printing progress messages. Exclude to disable.", true)] bool progress, [Flag("success", 's', "Include to enable printing success messages. Exclude to disable.", true)] bool success, [Flag("error", 'e', "Include to enable printing error messages. Exclude to disable.", true)] bool error, [Flag("notice", 'n', "Include to enable printing notice messages. Exclude to disable.", true)] bool notice, [Flag("warning", 'w', "Include to enable printing warning messages. Exclude to disable.", true)] bool warning, [Flag("exception", 'x', "Include to enable printing exception messages. Exclude to disable.", true)] bool exception, [Flag("uncat", 'u', "Include to enable printing uncategorized debugging messages. Exclude to disable.", true)] bool uncat, [Flag("all", 'a', "Include to enable printing all messages. Exclude to disable.", true)] bool all, [Flag("none", 'n', "Include to disable printing all messages. Exclude to disable.", true)] bool none) { if (all && none) { ConsoleBase.WriteCommandResponse(ConsoleBase.Colors.BrightRed, "The '--all' and '--none' flags are mutually exclusive. You cannot include both of these.\r\n"); return; } else if (all) { Options.Instance.DebugLevels = DebugLevels.All; } else if (none) { Options.Instance.DebugLevels = DebugLevels.None; } else if (!debug && !progress && !success && !error && !notice && !exception && !uncat) { CurrentStatus(); return; } else { if (debug) { Options.Instance.DebugLevels = Options.Instance.DebugLevels | DebugLevels.Debug; } else { Options.Instance.DebugLevels = Options.Instance.DebugLevels & ~DebugLevels.Debug; } if (progress) { Options.Instance.DebugLevels = Options.Instance.DebugLevels | DebugLevels.Progress; } else { Options.Instance.DebugLevels = Options.Instance.DebugLevels & ~DebugLevels.Progress; } if (success) { Options.Instance.DebugLevels = Options.Instance.DebugLevels | DebugLevels.Success; } else { Options.Instance.DebugLevels = Options.Instance.DebugLevels & ~DebugLevels.Success; } if (error) { Options.Instance.DebugLevels = Options.Instance.DebugLevels | DebugLevels.Error; } else { Options.Instance.DebugLevels = Options.Instance.DebugLevels & ~DebugLevels.Error; } if (notice) { Options.Instance.DebugLevels = Options.Instance.DebugLevels | DebugLevels.Notice; } else { Options.Instance.DebugLevels = Options.Instance.DebugLevels & ~DebugLevels.Notice; } if (warning) { Options.Instance.DebugLevels = Options.Instance.DebugLevels | DebugLevels.Warning; } else { Options.Instance.DebugLevels = Options.Instance.DebugLevels & ~DebugLevels.Warning; } if (exception) { Options.Instance.DebugLevels = Options.Instance.DebugLevels | DebugLevels.Exception; } else { Options.Instance.DebugLevels = Options.Instance.DebugLevels & ~DebugLevels.Exception; } if (uncat) { Options.Instance.DebugLevels = Options.Instance.DebugLevels | DebugLevels.Uncategorized; } else { Options.Instance.DebugLevels = Options.Instance.DebugLevels & ~DebugLevels.Uncategorized; } } CurrentStatus(); }
public void ConfigureLevels( [Flag("Debug", "Include to enable logging debug messages.", true)] bool debug, [Flag("Notices", "Include to enable logging notices.", true)] bool notices, [Flag("Warnings", "Include to enable logging warnings.", true)] bool warnings, [Flag("Errors", "Include to enable logging errors.", true)] bool errors, [Flag("Exceptions", "Include to enable logging exceptions.", true)] bool exceptions, [Flag("All", "Include to enable logging all messages.", true)] bool all, [Flag("None", "Include to disable logging all messages.", true)] bool none) { if (all && none) { ConsoleBase.WriteCommandResponse(ConsoleBase.Colors.BrightRed, "The '--all' and '--none' flags are mutually exclusive. You cannot include both of these.{0}", ConsoleBase.NewLine); return; } else if (all) { Options.Instance.LogLevels = LogLevels.All; } else if (none) { Options.Instance.LogLevels = LogLevels.None; } else if (!debug && !notices && !warnings && !errors && !exceptions) { PrintCurrentConfiguration(); return; } else { if (debug) { Options.Instance.LogLevels = Options.Instance.LogLevels | LogLevels.Debug; } else { Options.Instance.LogLevels = Options.Instance.LogLevels & ~LogLevels.Debug; } if (notices) { Options.Instance.LogLevels = Options.Instance.LogLevels | LogLevels.Notice; } else { Options.Instance.LogLevels = Options.Instance.LogLevels & ~LogLevels.Notice; } if (warnings) { Options.Instance.LogLevels = Options.Instance.LogLevels | LogLevels.Warning; } else { Options.Instance.LogLevels = Options.Instance.LogLevels & ~LogLevels.Warning; } if (errors) { Options.Instance.LogLevels = Options.Instance.LogLevels | LogLevels.Error; } else { Options.Instance.LogLevels = Options.Instance.LogLevels & ~LogLevels.Error; } if (exceptions) { Options.Instance.LogLevels = Options.Instance.LogLevels | LogLevels.Exception; } else { Options.Instance.LogLevels = Options.Instance.LogLevels & ~LogLevels.Exception; } if ((int)Options.Instance.LogLevels > 1) { Options.Instance.LogLevels = Options.Instance.LogLevels & ~LogLevels.None; } else { Options.Instance.LogLevels = LogLevels.None; } } PrintCurrentConfiguration(); }
private Action <string> ValidateWriter(Action <string> writer) { return(writer != null ? writer : msg => ConsoleBase.WriteCommandResponse(msg)); }