/
githubmirror
/
aspnetcore
Обзор
Документация
Войти
/
githubmirror
/
aspnetcore
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/Tools/Shared/CommandLine/CommandLineApplicationExtensions.cs
53 строки
2 KB
Eric Erhardt
Update SDK to 8.0.100-rc.1.23381.2 (#49761)
01 авг 2023, 02:33
Не верифицирован
01 авг 2023, 02:33
94f1088
Код
Авторство
О чём код?
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System; using System.Reflection; using System.Threading.Tasks; namespace Microsoft.Extensions.CommandLineUtils; internal static class CommandLineApplicationExtensions { public static CommandOption HelpOption(this CommandLineApplication app) => app.HelpOption("-?|-h|--help"); public static CommandOption VerboseOption(this CommandLineApplication app) => app.Option("-v|--verbose", "Show verbose output", CommandOptionType.NoValue, inherited: true); public static void OnExecute(this CommandLineApplication app, Action action) => app.OnExecute(() => { action(); return 0; }); public static CommandOption Option(this CommandLineApplication command, string template, string description) => command.Option( template, description, #if NETCOREAPP template.Contains('<') #else template.IndexOf('<') != -1 #endif ? template.EndsWith(">...", StringComparison.Ordinal) ? CommandOptionType.MultipleValue : CommandOptionType.SingleValue : CommandOptionType.NoValue); public static void VersionOptionFromAssemblyAttributes(this CommandLineApplication app) => app.VersionOptionFromAssemblyAttributes(typeof(CommandLineApplicationExtensions).Assembly); 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; } }