Skip to content

Commit 5ad9779

Browse files
edvilmeForgind
andauthored
[Bootstrapper] System.CommandLine: Add help text and command (#388)
* Remove LocalizableStrings.Designer.cs * Use System.CommandLine * Add real command parser --------- Co-authored-by: Forgind <[email protected]>
1 parent f94350e commit 5ad9779

File tree

4 files changed

+62
-79
lines changed

4 files changed

+62
-79
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
}

src/dotnet-bootstrapper/LocalizableStrings.Designer.cs

-72
This file was deleted.

src/dotnet-bootstrapper/Program.cs

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
// Copyright (c) .NET Foundation and contributors. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4-
namespace Microsoft.DotNet.Tools.Bootstrapper
4+
using System.CommandLine;
5+
using System.CommandLine.Builder;
6+
using System.CommandLine.Parsing;
7+
using System.IO;
8+
using System.Threading.Tasks;
9+
namespace Microsoft.DotNet.Tools.Bootstrapper;
10+
11+
class Program
512
{
6-
internal class Program
13+
static int Main(string[] args)
714
{
8-
internal static int Main(string[] args)
9-
{
10-
return 0;
11-
}
15+
return BootstrapperCommandParser.BootstrapParser.InvokeAsync(args).Result;
1216
}
1317
}

test/dotnet-bootstrapper.Tests/EndToEndTests.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ internal void ItReturnsZeroOnExit()
3131
RedirectStandardOutput = true,
3232
RedirectStandardError = true,
3333
UseShellExecute = false,
34-
CreateNoWindow = true
34+
CreateNoWindow = true,
35+
Arguments = "--version"
3536
}
3637
};
3738

0 commit comments

Comments
 (0)