public void TestThatDefaultReturnedWhenNoSpecificDefaultButImplicitDefaultsWanted() { var arg = CreateArg <int>(); ArgumentUsageInfo.TryGetDefaultValue(arg, false, out object value).Should().BeTrue(); value.Should().Be(default(int)); }
public void BasicUsage() { var help = new ArgumentUsageInfo("Syntax", "Help", false); help.Syntax.Should().Be("Syntax"); help.Description.Should().Be("Help"); }
public void TestThatNonEdgeCaseDefaultIsReturned() { const string anyString = "Some default string"; var arg = CreateArg <string>(defaultValue: anyString); ArgumentUsageInfo.TryGetDefaultValue(arg, false, out object value).Should().BeTrue(); value.Should().Be(anyString); }
public void TestThatSyntaxSummaryUsesPreferenceForArgumentValue() { var argDef = GetArgumentDefinition(new ArgumentSetAttribute { Style = ArgumentSetStyle.GetOpt, PreferNamedArgumentValueAsSucceedingToken = true }); var usage = new ArgumentUsageInfo(argDef); usage.GetSyntaxSummary().Should().Be("--my-value <int>"); }
/// <summary> /// Sets the ignore flag on the info context so the usage generator skips this argument. /// </summary> /// <param name="info">The info about the argument we're hiding</param> public override void BeforeGenerateUsage(ArgumentUsageInfo info) { info.Ignore = true; }
/// <summary> /// sets the ignroe flag on the info object /// </summary> /// <param name="info">the context used to modify the usage documentation</param> public override void BeforeGenerateUsage(ArgumentUsageInfo info) { // TODO P0 - Add a test that exercises this info.Ignore = true; }
public void Generate(string[] eventStoreBinaryPaths, string outputPath) { var documentation = String.Empty; foreach (var eventStoreBinaryPath in eventStoreBinaryPaths) { if (!Directory.Exists(eventStoreBinaryPath)) { Console.WriteLine("The path <{0}> does not exist", eventStoreBinaryPath); continue; } foreach (var assemblyFilePath in new DirectoryInfo(eventStoreBinaryPath).GetFiles().Where(x => x.Name.Contains("EventStore") && x.Name.EndsWith("exe"))) { var assembly = Assembly.LoadFrom(assemblyFilePath.FullName); var optionTypes = assembly.GetTypes().Where(x => typeof(IOptions).IsAssignableFrom(x)); foreach (var optionType in optionTypes) { var optionConstructor = optionType.GetConstructor(new Type[] { }); var options = optionConstructor.Invoke(null); var optionDocumentation = String.Format("###{0}{1}", options.GetType().Name, Environment.NewLine); var properties = options.GetType().GetProperties(); var currentGroup = String.Empty; foreach (var property in properties.OrderBy(x => x.Attr<ArgDescriptionAttribute>().Group)) { var parameterRow = String.Empty; if (currentGroup != property.Attr<ArgDescriptionAttribute>().Group) { currentGroup = property.Attr<ArgDescriptionAttribute>().Group; optionDocumentation += String.Format("{0}### {1}{0}{0}", Environment.NewLine, currentGroup); optionDocumentation += String.Format("| Parameter | Environment *(all prefixed with EVENTSTORE_)* | Yaml | Description |{0}", Environment.NewLine); optionDocumentation += String.Format("| --------- | --------------------------------------------- | ---- | ----------- |{0}", Environment.NewLine); } var parameterDefinition = new ArgumentUsageInfo(property); var parameterUsageFormat = "-{0}=VALUE<br/>"; var parameterUsage = String.Empty; foreach (var alias in parameterDefinition.Aliases) { parameterUsage += alias + "<br/>"; } parameterUsage += String.Format(parameterUsageFormat, parameterDefinition.Name); parameterRow += String.Format("|{0}", parameterUsage); parameterRow += String.Format("|{0}", NameTranslators.PrefixEnvironmentVariable(property.Name, "").ToUpper()); parameterRow += String.Format("|{0}", property.Name); var defaultValue = GetValues(property.GetValue(options, null)); var defaultString = defaultValue == "" ? "" : String.Format(" (Default: {0})", defaultValue); string[] possibleValues = null; if (property.PropertyType.IsEnum) { possibleValues = property.PropertyType.GetEnumNames(); } parameterRow += String.Format("|{0}{1} {2}|{3}", property.Attr<ArgDescriptionAttribute>().Description, defaultString, possibleValues != null ? "Possible Values:" + String.Join(",", possibleValues) : String.Empty, Environment.NewLine); optionDocumentation += parameterRow; } optionDocumentation += Environment.NewLine; documentation += optionDocumentation; } } if (!String.IsNullOrEmpty(documentation)) { Console.WriteLine("Writing generated document to {0}", outputPath); File.WriteAllText(outputPath, documentation); } else { Console.Error.WriteLine("The generated document is empty, please ensure that the event store binary paths that you supplied are correct."); } } }
public void Generate(string[] eventStoreBinaryPaths, string outputPath) { var documentation = String.Empty; foreach (var eventStoreBinaryPath in eventStoreBinaryPaths) { if (!Directory.Exists(eventStoreBinaryPath)) { Console.WriteLine("The path <{0}> does not exist", eventStoreBinaryPath); continue; } foreach (var assemblyFilePath in new DirectoryInfo(eventStoreBinaryPath).GetFiles().Where(x => x.Name.Contains("EventStore") && x.Name.EndsWith("exe"))) { var assembly = Assembly.LoadFrom(assemblyFilePath.FullName); var optionTypes = assembly.GetTypes().Where(x => typeof(IOptions).IsAssignableFrom(x)); foreach (var optionType in optionTypes) { var optionConstructor = optionType.GetConstructor(new Type[] { }); var options = optionConstructor.Invoke(null); var optionDocumentation = String.Format("###{0}{1}", options.GetType().Name, Environment.NewLine); var properties = options.GetType().GetProperties(); var currentGroup = String.Empty; foreach (var property in properties.OrderBy(x => x.Attr <ArgDescriptionAttribute>().Group)) { var parameterRow = String.Empty; if (currentGroup != property.Attr <ArgDescriptionAttribute>().Group) { currentGroup = property.Attr <ArgDescriptionAttribute>().Group; optionDocumentation += String.Format("{0}### {1}{0}{0}", Environment.NewLine, currentGroup); optionDocumentation += String.Format("| Parameter | Environment *(all prefixed with EVENTSTORE_)* | Yaml | Description |{0}", Environment.NewLine); optionDocumentation += String.Format("| --------- | --------------------------------------------- | ---- | ----------- |{0}", Environment.NewLine); } var parameterDefinition = new ArgumentUsageInfo(property); var parameterUsageFormat = "-{0}=VALUE<br/>"; var parameterUsage = String.Empty; foreach (var alias in parameterDefinition.Aliases) { parameterUsage += alias + "<br/>"; } parameterUsage += String.Format(parameterUsageFormat, parameterDefinition.Name); parameterRow += String.Format("|{0}", parameterUsage); parameterRow += String.Format("|{0}", NameTranslators.PrefixEnvironmentVariable(property.Name, "").ToUpper()); parameterRow += String.Format("|{0}", property.Name); var defaultValue = GetValues(property.GetValue(options, null)); var defaultString = defaultValue == "" ? "" : String.Format(" (Default: {0})", defaultValue); string[] possibleValues = null; if (property.PropertyType.IsEnum) { possibleValues = property.PropertyType.GetEnumNames(); } parameterRow += String.Format("|{0}{1} {2}|{3}", property.Attr <ArgDescriptionAttribute>().Description, defaultString, possibleValues != null ? "Possible Values:" + String.Join(",", possibleValues) : String.Empty, Environment.NewLine); optionDocumentation += parameterRow; } optionDocumentation += Environment.NewLine; documentation += optionDocumentation; } } if (!String.IsNullOrEmpty(documentation)) { Console.WriteLine("Writing generated document to {0}", outputPath); File.WriteAllText(outputPath, documentation); } else { Console.Error.WriteLine("The generated document is empty, please ensure that the event store binary paths that you supplied are correct."); } } }
public void TestThatDefaultNeverReturnedWhenItIsEmptyString() { var arg = CreateArg <string>(defaultValue: string.Empty); ArgumentUsageInfo.TryGetDefaultValue(arg, false, out object value).Should().BeFalse(); }
public void TestThatDefaultNeverReturnedWhenItIsFalse() { var arg = CreateArg <bool>(); ArgumentUsageInfo.TryGetDefaultValue(arg, false, out object value).Should().BeFalse(); }
public void TestThatNoDefaultReturnedWhenNoSpecificDefaultAndOnlyExplicitDefaultsWanted() { var arg = CreateArg <int>(); ArgumentUsageInfo.TryGetDefaultValue(arg, true, out object value).Should().BeFalse(); }
public void TestThatDefaultValueReturnsFalseForRequiredArgs() { var arg = CreateArg <int>(required: true, defaultValue: Any.PositiveInt()); ArgumentUsageInfo.TryGetDefaultValue(arg, false, out object value).Should().BeFalse(); }