Add --version options to dotnet-watch and dotnet-sql-cache
This commit is contained in:
parent
4a64ef857c
commit
e0f85971a3
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using Microsoft.DotNet.Watcher.Tools;
|
||||
using Microsoft.Extensions.CommandLineUtils;
|
||||
using Microsoft.Extensions.Tools.Internal;
|
||||
|
|
@ -61,6 +62,7 @@ Examples:
|
|||
CommandOptionType.NoValue);
|
||||
var optVerbose = app.Option("-v|--verbose", "Show verbose output",
|
||||
CommandOptionType.NoValue);
|
||||
app.VersionOptionFromAssemblyAttributes(typeof(Program).GetTypeInfo().Assembly);
|
||||
|
||||
app.OnExecute(() =>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
using System;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Reflection;
|
||||
using Microsoft.Extensions.CommandLineUtils;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
|
|
@ -36,11 +37,14 @@ namespace Microsoft.Extensions.Caching.SqlConfig.Tools
|
|||
var description = "Creates table and indexes in Microsoft SQL Server database " +
|
||||
"to be used for distributed caching";
|
||||
|
||||
var app = new CommandLineApplication();
|
||||
app.Name = "dotnet-sql-cache";
|
||||
app.Description = description;
|
||||
|
||||
var app = new CommandLineApplication
|
||||
{
|
||||
Name = "dotnet sql-cache",
|
||||
FullName = "SQL Server Cache Command Line Tool",
|
||||
Description = description,
|
||||
};
|
||||
app.HelpOption("-?|-h|--help");
|
||||
app.VersionOptionFromAssemblyAttributes(typeof(Program).GetTypeInfo().Assembly);
|
||||
|
||||
app.Command("create", command =>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
"outputName": "dotnet-sql-cache",
|
||||
"emitEntryPoint": true,
|
||||
"warningsAsErrors": true,
|
||||
"keyFile": "../../tools/Key.snk"
|
||||
"keyFile": "../../tools/Key.snk",
|
||||
"compile": "../Shared/CommandLineApplicationExtensions.cs"
|
||||
},
|
||||
"description": "Command line tool to create tables and indexes in a Microsoft SQL Server database for distributed caching.",
|
||||
"packOptions": {
|
||||
|
|
|
|||
|
|
@ -3,18 +3,19 @@
|
|||
|
||||
using System.Reflection;
|
||||
using Microsoft.Extensions.CommandLineUtils;
|
||||
using Microsoft.Extensions.SecretManager.Tools.Internal;
|
||||
using Microsoft.Extensions.Tools.Internal;
|
||||
|
||||
namespace Microsoft.Extensions.SecretManager.Tools.Internal
|
||||
namespace Microsoft.Extensions.SecretManager.Tools
|
||||
{
|
||||
public class CommandLineOptions
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public bool IsVerbose { get; set; }
|
||||
public bool IsHelp { get; set; }
|
||||
public string Project { get; set; }
|
||||
public ICommand Command { get; set; }
|
||||
public string Configuration { get; set; }
|
||||
public string Configuration { get; private set; }
|
||||
public string Id { get; private set; }
|
||||
public bool IsHelp { get; private set; }
|
||||
public bool IsVerbose { get; private set; }
|
||||
public string Project { get; private set; }
|
||||
|
||||
public static CommandLineOptions Parse(string[] args, IConsole console)
|
||||
{
|
||||
|
|
@ -28,7 +29,7 @@ namespace Microsoft.Extensions.SecretManager.Tools.Internal
|
|||
};
|
||||
|
||||
app.HelpOption();
|
||||
app.VersionOption("--version", GetInformationalVersion());
|
||||
app.VersionOptionFromAssemblyAttributes(typeof(Program).GetTypeInfo().Assembly);
|
||||
|
||||
var optionVerbose = app.Option("-v|--verbose", "Verbose output",
|
||||
CommandOptionType.NoValue, inherited: true);
|
||||
|
|
@ -68,17 +69,5 @@ namespace Microsoft.Extensions.SecretManager.Tools.Internal
|
|||
|
||||
return options;
|
||||
}
|
||||
|
||||
private static string GetInformationalVersion()
|
||||
{
|
||||
var assembly = typeof(Program).GetTypeInfo().Assembly;
|
||||
var attribute = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>();
|
||||
|
||||
var versionAttribute = attribute == null ?
|
||||
assembly.GetName().Version.ToString() :
|
||||
attribute.InformationalVersion;
|
||||
|
||||
return versionAttribute;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
|
||||
namespace Microsoft.Extensions.CommandLineUtils
|
||||
{
|
||||
public static class UserSecretsCommandLineExtensions
|
||||
{
|
||||
public static CommandOption HelpOption(this CommandLineApplication app)
|
||||
{
|
||||
return app.HelpOption("-?|-h|--help");
|
||||
}
|
||||
|
||||
public static void OnExecute(this CommandLineApplication app, Action action)
|
||||
{
|
||||
app.OnExecute(() =>
|
||||
{
|
||||
action();
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Microsoft.Extensions.CommandLineUtils
|
||||
{
|
||||
public static class CommandLineApplicationExtensions
|
||||
{
|
||||
public static CommandOption HelpOption(this CommandLineApplication app)
|
||||
=> app.HelpOption("-?|-h|--help");
|
||||
|
||||
public static void OnExecute(this CommandLineApplication app, Action action)
|
||||
=> app.OnExecute(() =>
|
||||
{
|
||||
action();
|
||||
return 0;
|
||||
});
|
||||
|
||||
public static void VersionOptionFromAssemblyAttributes(this CommandLineApplication app, Assembly assembly)
|
||||
=> app.VersionOption("--version", GetInformationalVersion(assembly));
|
||||
|
||||
private static string GetInformationalVersion(Assembly assembly)
|
||||
{
|
||||
var attribute = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>();
|
||||
|
||||
var versionAttribute = attribute == null
|
||||
? assembly.GetName().Version.ToString()
|
||||
: attribute.InformationalVersion;
|
||||
|
||||
return versionAttribute;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue