public void WriteIndividualHelpToConsole(ArgumentKey k) { ConsoleColorState colorState = RugConsole.ColorState; IArgumentValue value2 = this.m_Switches[k]; RugConsole.Write(ConsoleVerbosity.Silent, ConsoleThemeColor.SubText, new string('-', RugConsole.BufferWidth) + "["); RugConsole.Write(ConsoleVerbosity.Silent, ConsoleThemeColor.TitleText, k.Prefix + k.Symbol.ToUpper()); RugConsole.Write(ConsoleVerbosity.Silent, ConsoleThemeColor.Text, value2.ArgumentString()); RugConsole.Write(ConsoleVerbosity.Silent, ConsoleThemeColor.SubText, "] "); RugConsole.Write(ConsoleVerbosity.Silent, ConsoleThemeColor.TitleText, " " + k.Prefix + k.Symbol.ToUpper()); if (k.Name.ToUpper().StartsWith(k.Symbol.ToUpper())) { RugConsole.WriteLine(ConsoleVerbosity.Silent, ConsoleThemeColor.Text, k.Name.Substring(k.Symbol.Length).PadRight(15 - k.Symbol.Length)); } else { RugConsole.WriteLine(ConsoleVerbosity.Silent, ConsoleThemeColor.Text, (" (" + k.Name + ")").PadRight(15 - k.Symbol.Length)); } RugConsole.WriteLine(ConsoleVerbosity.Silent, ConsoleThemeColor.Text1, " " + value2.ShortHelp); RugConsole.WriteLine(ConsoleVerbosity.Silent, ConsoleThemeColor.TitleText, ""); if (Helper.IsNotNullOrEmpty(value2.Help)) { RugConsole.WriteInterpreted(ConsoleThemeColor.TitleText, value2.Help, 2, 2); RugConsole.WriteLine(ConsoleVerbosity.Silent, ""); } RugConsole.ColorState = colorState; }
public string GetShortArgumentsUsage() { StringBuilder builder = new StringBuilder(); new StringBuilder(); builder.AppendLine(this.m_Description); builder.AppendLine(""); builder.Append(this.m_AppName.ToUpper() + " "); if (this.m_FirstArgument != null) { builder.Append("<" + this.m_FirstArgument.ArgumentString().Trim() + "> "); } if (this.m_DefaultArgument != null) { builder.Append("<" + this.m_DefaultArgument.ArgumentString().Trim() + "> "); } foreach (ArgumentKey key in this.m_Switches.Keys) { IArgumentValue value2 = this.m_Switches[key]; builder.Append("[" + key.Prefix + key.Symbol.ToUpper() + value2.ArgumentString() + "] "); } if (this.HasApplicationAbout) { builder.Append("/?? "); } if (this.HasApplicationDocument) { builder.Append("/?D <" + Strings.ArgumentParser_Documentation_NameForPath + "> "); } builder.AppendLine(""); builder.AppendLine(""); return(builder.ToString()); }
/// <summary> /// Defines a new value in this type. /// </summary> /// <param name="value">Value to define.</param> protected void AddValue(IArgumentValue value) { _values.Add(value); AddToValueNameMap(_valuesByCaseSensitiveName, value); AddToValueNameMap(_valuesByCaseInsensitiveName, value); AddToValueMap(_valuesByValue, value); }
public static T AddValue <T>(this T argumentsBuilder, IArgumentValue value) where T : IArgumentsBuilder { argumentsBuilder.AddToken(value); return(argumentsBuilder); }
public string GetLongArgumentsUsage() { StringBuilder builder = new StringBuilder(); foreach (ArgumentKey key in this.m_Switches.Keys) { IArgumentValue value2 = this.m_Switches[key]; string str = key.Symbol.ToUpper(); if (key.Name.ToUpper().StartsWith(key.Symbol.ToUpper())) { str = str + key.Name.Substring(key.Symbol.Length); } else { str = str + " (" + key.Name + ")"; } builder.AppendLine(" " + key.Prefix + str.PadRight(15) + " " + value2.ShortHelp); } if (this.HasApplicationAbout) { builder.AppendLine(" " + "/??".PadRight(15) + " " + Strings.ArgumentParser_AboutScreen_Title); } if (this.HasApplicationDocument) { builder.AppendLine(" " + "/?D".PadRight(15) + " " + Strings.ArgumentParser_DocumentGenerator_Title); } return(this.GetShortArgumentsUsage() + builder.ToString()); }
public string GetIndividualHelpString(ArgumentKey k) { StringBuilder builder = new StringBuilder(); IArgumentValue value2 = this.m_Switches[k]; builder.Append("[" + k.Prefix + k.Symbol.ToUpper() + value2.ArgumentString() + "] "); string str = k.Symbol.ToUpper(); if (k.Name.ToUpper().StartsWith(k.Symbol.ToUpper())) { str = str + k.Name.Substring(k.Symbol.Length); } else { str = str + " (" + k.Name + ")"; } builder.AppendLine(" " + k.Prefix + str); builder.AppendLine(" " + value2.ShortHelp); builder.AppendLine(); if (Helper.IsNotNullOrEmpty(value2.Help)) { builder.AppendLine(ConsoleFormatter.StripFormat(value2.Help)); builder.AppendLine(); } return(builder.ToString()); }
public override bool Parse(ArgumentParser parser, string key, string[] values, ref int index) { if ((index + 1) < values.Length) { string str = values[index + 1]; string str2 = str; if (str.StartsWith("-") || str.StartsWith("+")) { str2 = ConsoleChars.GetMathsChar(ConsoleMathsChars.PlusMinus) + key.Substring(1); } ArgumentKey outKey = null; IArgumentValue forKey = null; if (parser.ContainsKey(str)) { forKey = parser.GetForKey(str, out outKey); } else if (!str2.Equals(str) && parser.ContainsKey(str2)) { forKey = parser.GetForKey(str2, out outKey); } if ((outKey == null) || (forKey == null)) { this.SetValue(values[index + 1]); index++; } } return(false); }
public void Add(string prefix, string symbol, string key, IArgumentValue value) { if (this.ContainsSymbol(symbol)) { throw new Exception(string.Format(Strings.ArgumentParser_Add_SymbolInUse, symbol)); } this.m_Switches.Add(new ArgumentKey(prefix, key, symbol), value); }
public void Add(string prefix, string symbol, string key, IArgumentValue value) { if (this.ContainsSymbol(symbol)) { throw new Exception(string.Format(Strings.ArgumentParser_Add_SymbolInUse, symbol)); } this.m_Switches.Add(new ArgumentKey(prefix, key, symbol), value); }
private static IArgument Build <T>(string name, T value, Func <T, IArgumentValue> valueFactory) { name = name.MustNotBeNullOrWhiteSpace("A GraphQL argument name cannot be null or white space.", nameof(name)) .MustBeValidGraphQLName(nameof(name)); IArgumentValue argValue = value == null ? new NullArgumentValue() : valueFactory(value); return(new Argument(name, argValue)); }
/// <summary> /// Tries to look up the <see cref="IArgumentValue"/> corresponding with /// the given object. /// </summary> /// <param name="value">Object to look up.</param> /// <param name="argValue">On success, receives the object's value.</param> /// <returns>true on success; false otherwise.</returns> public bool TryGetValue(object value, out IArgumentValue argValue) { if (!_valuesByValue.TryGetValue(value, out IArgumentValue enumArgValue)) { argValue = null; return(false); } argValue = enumArgValue; return(true); }
private static void AddToValueMap(Dictionary <object, IArgumentValue> map, IArgumentValue value) { // We do our best to add each value to the map; but if there // are multiple members that share a value, then the first // one will "win". We don't bother trying to maintain a // multimap. if (!map.ContainsKey(value.Value)) { map.Add(value.Value, value); } }
/// <inheritdoc /> public bool TryGetValue(string key, out IArgumentValue value) { if (!ContainsKey(key)) { value = default; return(false); } value = this[key]; return(true); }
private ArgumentValueSummary Summarize(ArgumentDefinition arg, IArgumentValue value) { var commandAttrib = value.GetAttributes <CommandAttribute>().SingleOrDefault(); var commandType = commandAttrib?.GetImplementingType(arg.ArgumentType.Type); return(new ArgumentValueSummary { description = value.Description, name = value.LongName, short_name = value.ShortName, command_type = commandType.Name, command_argument_set = Summarize(GetArgumentSetFor(commandType)) }); }
public void WriteLongArgumentsUsage() { ConsoleColorState colorState = RugConsole.ColorState; this.WriteShortArgumentsUsage(); if ((this.m_FirstArgument != null) && Helper.IsNotNullOrEmpty(this.m_FirstArgument.Help)) { RugConsole.WriteLine(ConsoleVerbosity.Silent, ConsoleThemeColor.SubText2, " <" + this.m_FirstArgument.ArgumentString().Trim() + ">"); RugConsole.WriteWrapped(ConsoleThemeColor.Text1, this.m_FirstArgument.Help, 4, 4); RugConsole.WriteLine(ConsoleVerbosity.Silent, ""); } if ((this.m_DefaultArgument != null) && Helper.IsNotNullOrEmpty(this.m_DefaultArgument.Help)) { RugConsole.WriteLine(ConsoleVerbosity.Silent, ConsoleThemeColor.SubText3, " <" + this.m_DefaultArgument.ArgumentString().Trim() + ">"); RugConsole.WriteWrapped(ConsoleThemeColor.Text1, this.m_DefaultArgument.Help, 4, 2); RugConsole.WriteLine(ConsoleVerbosity.Silent, ""); } foreach (ArgumentKey key in this.m_Switches.Keys) { IArgumentValue value2 = this.m_Switches[key]; string str = key.Prefix + key.Symbol.ToUpper(); RugConsole.Write(ConsoleVerbosity.Silent, ConsoleThemeColor.TitleText, " " + str); if (key.Name.ToUpper().StartsWith(key.Symbol.ToUpper())) { RugConsole.Write(ConsoleVerbosity.Silent, ConsoleThemeColor.Text, key.Name.Substring(key.Symbol.Length).PadRight(0x12 - str.Length)); } else { RugConsole.Write(ConsoleVerbosity.Silent, ConsoleThemeColor.Text, (" (" + key.Name + ")").PadRight(0x12 - str.Length)); } RugConsole.WriteLine(ConsoleVerbosity.Silent, ConsoleThemeColor.Text1, " " + value2.ShortHelp); } if (this.HasApplicationAbout) { RugConsole.Write(ConsoleVerbosity.Silent, ConsoleThemeColor.WarningColor2, " " + "/?? ".PadRight(0x12)); RugConsole.WriteLine(ConsoleVerbosity.Silent, ConsoleThemeColor.Text1, " " + Strings.ArgumentParser_AboutScreen_Title); } if (this.HasApplicationDocument) { RugConsole.Write(ConsoleVerbosity.Silent, ConsoleThemeColor.WarningColor2, " " + "/?D ".PadRight(0x12)); RugConsole.WriteLine(ConsoleVerbosity.Silent, ConsoleThemeColor.Text1, " " + Strings.ArgumentParser_DocumentGenerator_Title); } RugConsole.ColorState = colorState; }
public void Add(string prefix, string key, IArgumentValue value) { if (this.ContainsName(key)) { throw new Exception(string.Format(Strings.ArgumentParser_Add_AllreadyContainsKey, key)); } int length = 1; int num2 = key.Length; while (length < num2) { if (!this.ContainsSymbol(key.Substring(0, length))) { this.m_Switches.Add(new ArgumentKey(prefix, key, key.Substring(0, length)), value); return; } length++; } throw new Exception(string.Format(Strings.ArgumentParser_Add_CannotMatchSymbolForKey, key)); }
public void Add(string prefix, string key, IArgumentValue value) { if (this.ContainsName(key)) { throw new Exception(string.Format(Strings.ArgumentParser_Add_AllreadyContainsKey, key)); } int length = 1; int num2 = key.Length; while (length < num2) { if (!this.ContainsSymbol(key.Substring(0, length))) { this.m_Switches.Add(new ArgumentKey(prefix, key, key.Substring(0, length)), value); return; } length++; } throw new Exception(string.Format(Strings.ArgumentParser_Add_CannotMatchSymbolForKey, key)); }
private ColoredMultistring FormatEnumValueInfo(IArgumentValue value) { var builder = new ColoredMultistringBuilder(); builder.Append(new ColoredString(value.DisplayName, ParameterNameForegroundColor)); if (!string.IsNullOrEmpty(value.Description)) { builder.Append(" - "); builder.Append(value.Description); } if (!string.IsNullOrEmpty(value.ShortName)) { builder.Append(" ["); builder.Append(new ColoredString(Strings.UsageInfoShortForm, ParameterMetadataForegroundColor)); builder.Append(" "); builder.Append(new ColoredString(value.ShortName, NameForegroundColor)); builder.Append("]"); } return(builder.ToMultistring()); }
private ParameterEntry GetEnumValueInfo(IArgumentValue value) { var syntaxBuilder = new ColoredMultistringBuilder(); if (_options.Arguments.ShortName == ArgumentShortNameHelpMode.IncludeWithLongName && !string.IsNullOrEmpty(value.ShortName)) { syntaxBuilder.Append(new ColoredString(value.ShortName, _options.Arguments?.ArgumentNameColor)); syntaxBuilder.Append(", "); } syntaxBuilder.Append(new ColoredString(value.DisplayName, _options.Arguments?.ArgumentNameColor)); var descBuilder = new ColoredMultistringBuilder(); if (!string.IsNullOrEmpty(value.Description)) { descBuilder.Append(value.Description); } if (_options.Arguments.ShortName == ArgumentShortNameHelpMode.AppendToDescription && !string.IsNullOrEmpty(value.ShortName)) { descBuilder.Append(" ["); descBuilder.Append(new ColoredString(Strings.UsageInfoShortForm, _options.Arguments.MetadataColor)); descBuilder.Append(" "); descBuilder.Append(new ColoredString(value.ShortName, _options.Arguments?.ArgumentNameColor)); descBuilder.Append("]"); } return(new ParameterEntry { Syntax = syntaxBuilder.ToMultistring(), Description = descBuilder.ToMultistring(), InlineEnumEntries = null }); }
public void WriteShortArgumentsUsage() { ConsoleColorState colorState = RugConsole.ColorState; RugConsole.ForegroundThemeColor = ConsoleThemeColor.TitleText; RugConsole.WriteLine(ConsoleVerbosity.Silent, this.m_Description); RugConsole.WriteLine(ConsoleVerbosity.Silent); int count = this.m_AppName.Length + 1; int num2 = count; RugConsole.Write(ConsoleVerbosity.Silent, this.m_AppName.ToUpper() + " "); if (this.m_FirstArgument != null) { string str = "<" + this.m_FirstArgument.ArgumentString().Trim() + "> "; num2 += str.Length + str.Length; if (num2 > RugConsole.BufferWidth) { num2 = count; RugConsole.WriteLine(); RugConsole.Write(new string(' ', count)); } RugConsole.Write(ConsoleVerbosity.Silent, ConsoleThemeColor.SubText2, str); } if (this.m_DefaultArgument != null) { string str2 = "<" + this.m_DefaultArgument.ArgumentString().Trim() + "> "; num2 += str2.Length; if (num2 > RugConsole.BufferWidth) { num2 = count + str2.Length; RugConsole.WriteLine(); RugConsole.Write(new string(' ', count)); } RugConsole.Write(ConsoleVerbosity.Silent, ConsoleThemeColor.SubText3, str2); } foreach (ArgumentKey key in this.m_Switches.Keys) { IArgumentValue value2 = this.m_Switches[key]; int num3 = ((key.Prefix.Length + key.Symbol.Length) + value2.ArgumentString().Length) + 3; num2 += num3; if (num2 > RugConsole.BufferWidth) { num2 = count + num3; RugConsole.WriteLine(); RugConsole.Write(new string(' ', count)); } RugConsole.Write(ConsoleVerbosity.Silent, ConsoleThemeColor.SubText, "["); RugConsole.Write(ConsoleVerbosity.Silent, ConsoleThemeColor.TitleText, key.Prefix + key.Symbol.ToUpper()); RugConsole.Write(ConsoleVerbosity.Silent, ConsoleThemeColor.Text, value2.ArgumentString()); RugConsole.Write(ConsoleVerbosity.Silent, ConsoleThemeColor.SubText, "] "); } if (this.HasApplicationAbout) { int num4 = 4; num2 += num4; if (num2 > RugConsole.BufferWidth) { num2 = count + num4; RugConsole.WriteLine(); RugConsole.Write(new string(' ', count)); } RugConsole.Write(ConsoleVerbosity.Silent, ConsoleThemeColor.WarningColor2, "/?? "); } if (this.HasApplicationDocument) { int num5 = 11; num2 += num5; if (num2 > RugConsole.BufferWidth) { num2 = count + num5; RugConsole.WriteLine(); RugConsole.Write(new string(' ', count)); } RugConsole.Write(ConsoleVerbosity.Silent, ConsoleThemeColor.WarningColor2, "/?D <path> "); } RugConsole.ColorState = colorState; RugConsole.WriteLine(ConsoleVerbosity.Silent); RugConsole.WriteLine(ConsoleVerbosity.Silent); }
public void Parse(string[] args) { ConsoleColorState colorState = RugConsole.ColorState; try { if (args.Length > 0) { int num = 0; StringListArgument firstArgument = null; if (args[0] == "/?") { if (args.Length == 1) { this.WriteLongArgumentsUsage(); } else { this.WriteShortArgumentsUsage(); } this.m_HelpMode = true; num++; } else if (args[0] == "/??") { this.WriteApplicationAboutToConsole(true); this.m_HelpMode = true; num++; } else { if (args[0].Equals("/?D", StringComparison.CurrentCultureIgnoreCase)) { string str; if (args.Length > 1) { str = args[1]; } else { str = Path.Combine(Environment.CurrentDirectory, this.m_AppName + " Documentation.txt"); } this.WriteApplicationDocumentationToPath(str); this.m_HelpMode = true; return; } if (this.m_FirstArgument != null) { this.m_FirstArgument.SetValue(args[0]); this.m_FirstArgument.Defined = true; if (this.m_FirstArgument is StringListArgument) { firstArgument = this.m_FirstArgument as StringListArgument; } num++; } } int index = num; int length = args.Length; while (index < length) { string str2 = args[index]; string str3 = str2; if (str2.StartsWith("-") || str2.StartsWith("+")) { str3 = ConsoleChars.GetMathsChar(ConsoleMathsChars.PlusMinus) + str2.Substring(1); } ArgumentKey outKey = null; IArgumentValue forKey = null; if (this.ContainsKey(str2)) { forKey = this.GetForKey(str2, out outKey); } else if (!str3.Equals(str2) && this.ContainsKey(str3)) { forKey = this.GetForKey(str3, out outKey); } if ((outKey != null) && (forKey != null)) { if (this.m_HelpMode) { this.WriteIndividualHelpToConsole(outKey); } else { forKey.Defined = true; if (forKey.Parse(this, str2, args, ref index)) { firstArgument = forKey as StringListArgument; } else { firstArgument = null; } } } else if ((firstArgument != null) && !this.m_HelpMode) { firstArgument.SetValue(str2); } else { if ((this.m_DefaultArgument == null) || this.m_HelpMode) { throw new Exception(string.Format(Strings.ArgumentParser_InvalidSwitch, str2)); } this.m_DefaultArgument.SetValue(str2); } index++; } } } finally { RugConsole.ColorState = colorState; } }
public static NameValueArgument SetValue(this NameValueArgument nameValue, IArgumentValue value) { nameValue.Value = value; return(nameValue); }
/// <summary> /// Adds the given value to the provided name map. /// </summary> /// <param name="map">Map to add to.</param> /// <param name="value">The value to add.</param> private static void AddToValueNameMap(Dictionary <string, IArgumentValue> map, IArgumentValue value) { // We skip disallowed values. if (value.Disallowed) { return; } // Make sure the long name for the value isn't a duplicate. if (map.ContainsKey(value.LongName)) { throw new ArgumentOutOfRangeException(nameof(value), Strings.EnumValueLongNameIsInvalid); } // If explicitly provided, make sure the short name for the // value isn't a duplicate. if ((value.ShortName != null) && map.ContainsKey(value.ShortName)) { throw new ArgumentOutOfRangeException(nameof(value), Strings.EnumValueShortNameIsInvalid); } // Add the long and short name. map[value.LongName] = value; if (value.ShortName != null) { map[value.ShortName] = value; } }
public bool WasDefined(string name) { IArgumentValue forName = this.GetForName(name); return((forName != null) && forName.Defined); }
public Argument(string name, IArgumentValue value) { Name = name.MustBeValidGraphQLName(nameof(name)); Value = value ?? throw new ArgumentNullException(nameof(value)); }