Skip to content

Commit 5d4b2c8

Browse files
Add extension method to use automatic application version
1 parent 3acc90e commit 5d4b2c8

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/Spectre.Console.Cli/ConfiguratorExtensions.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public static IConfigurator SetApplicationName(this IConfigurator configurator,
8282
}
8383

8484
/// <summary>
85-
/// Overrides the auto-detected version of the application.
85+
/// Sets the version of the application.
8686
/// </summary>
8787
/// <param name="configurator">The configurator.</param>
8888
/// <param name="version">The version of application.</param>
@@ -98,6 +98,25 @@ public static IConfigurator SetApplicationVersion(this IConfigurator configurato
9898
return configurator;
9999
}
100100

101+
/// <summary>
102+
/// Uses the version retrieved from the <see cref="AssemblyInformationalVersionAttribute"/>
103+
/// as the application's version.
104+
/// </summary>
105+
/// <param name="configurator">The configurator.</param>
106+
/// <returns>A configurator that can be used to configure the application further.</returns>
107+
public static IConfigurator UseAssemblyInformationalVersion(this IConfigurator configurator)
108+
{
109+
if (configurator == null)
110+
{
111+
throw new ArgumentNullException(nameof(configurator));
112+
}
113+
114+
configurator.Settings.ApplicationVersion =
115+
VersionHelper.GetVersion(Assembly.GetEntryAssembly());
116+
117+
return configurator;
118+
}
119+
101120
/// <summary>
102121
/// Hides the <c>DEFAULT</c> column that lists default values coming from the
103122
/// <see cref="DefaultValueAttribute"/> in the options help text.

0 commit comments

Comments
 (0)