|
| 1 | +// Copyright (c) .NET Foundation and contributors. All rights reserved. |
| 2 | +// Licensed under the MIT license. See LICENSE file in the project root for full license information. |
| 3 | + |
| 4 | +using System; |
| 5 | +using System.CommandLine; |
| 6 | +using System.CommandLine.Builder; |
| 7 | +using System.CommandLine.Invocation; |
| 8 | +using System.CommandLine.Parsing; |
| 9 | +using System.Reflection; |
| 10 | + |
| 11 | +namespace Microsoft.DotNet.Tools.Bootstrapper |
| 12 | +{ |
| 13 | + internal static class BootstrapperCommandParser |
| 14 | + { |
| 15 | + public static Parser BootstrapParser; |
| 16 | + |
| 17 | + public static RootCommand BootstrapperRootCommand = new RootCommand("dotnet bootstrapper"); |
| 18 | + |
| 19 | + public static readonly Command VersionCommand = new Command("--version"); |
| 20 | + |
| 21 | + private static readonly Lazy<string> _assemblyVersion = |
| 22 | + new Lazy<string>(() => |
| 23 | + { |
| 24 | + var assembly = Assembly.GetEntryAssembly() ?? Assembly.GetExecutingAssembly(); |
| 25 | + var assemblyVersionAttribute = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>(); |
| 26 | + if (assemblyVersionAttribute == null) |
| 27 | + { |
| 28 | + return assembly.GetName().Version.ToString(); |
| 29 | + } |
| 30 | + else |
| 31 | + { |
| 32 | + return assemblyVersionAttribute.InformationalVersion; |
| 33 | + } |
| 34 | + }); |
| 35 | + |
| 36 | + static BootstrapperCommandParser() |
| 37 | + { |
| 38 | + BootstrapperRootCommand.AddCommand(VersionCommand); |
| 39 | + VersionCommand.Handler = CommandHandler.Create(() => |
| 40 | + { |
| 41 | + Console.WriteLine(_assemblyVersion.Value); |
| 42 | + }); |
| 43 | + |
| 44 | + BootstrapParser = new CommandLineBuilder(BootstrapperRootCommand) |
| 45 | + .UseDefaults() |
| 46 | + // .UseHelpBuilder(context => new UninstallHelpBuilder(context.Console)) |
| 47 | + .Build(); |
| 48 | + } |
| 49 | + } |
| 50 | +} |
0 commit comments