Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5ad9779

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 <12969783+Forgind@users.noreply.github.com>
1 parentf94350e commit5ad9779

File tree

4 files changed

+62
-79
lines changed

4 files changed

+62
-79
lines changed
Lines changed: 50 additions & 0 deletions
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+
usingSystem;
5+
usingSystem.CommandLine;
6+
usingSystem.CommandLine.Builder;
7+
usingSystem.CommandLine.Invocation;
8+
usingSystem.CommandLine.Parsing;
9+
usingSystem.Reflection;
10+
11+
namespaceMicrosoft.DotNet.Tools.Bootstrapper
12+
{
13+
internalstaticclassBootstrapperCommandParser
14+
{
15+
publicstaticParserBootstrapParser;
16+
17+
publicstaticRootCommandBootstrapperRootCommand=newRootCommand("dotnet bootstrapper");
18+
19+
publicstaticreadonlyCommandVersionCommand=newCommand("--version");
20+
21+
privatestaticreadonlyLazy<string>_assemblyVersion=
22+
newLazy<string>(()=>
23+
{
24+
varassembly=Assembly.GetEntryAssembly()??Assembly.GetExecutingAssembly();
25+
varassemblyVersionAttribute=assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>();
26+
if(assemblyVersionAttribute==null)
27+
{
28+
returnassembly.GetName().Version.ToString();
29+
}
30+
else
31+
{
32+
returnassemblyVersionAttribute.InformationalVersion;
33+
}
34+
});
35+
36+
staticBootstrapperCommandParser()
37+
{
38+
BootstrapperRootCommand.AddCommand(VersionCommand);
39+
VersionCommand.Handler=CommandHandler.Create(()=>
40+
{
41+
Console.WriteLine(_assemblyVersion.Value);
42+
});
43+
44+
BootstrapParser=newCommandLineBuilder(BootstrapperRootCommand)
45+
.UseDefaults()
46+
// .UseHelpBuilder(context => new UninstallHelpBuilder(context.Console))
47+
.Build();
48+
}
49+
}
50+
}

‎src/dotnet-bootstrapper/LocalizableStrings.Designer.cs

Lines changed: 0 additions & 72 deletions
This file was deleted.

‎src/dotnet-bootstrapper/Program.cs

Lines changed: 10 additions & 6 deletions
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-
namespaceMicrosoft.DotNet.Tools.Bootstrapper
4+
usingSystem.CommandLine;
5+
usingSystem.CommandLine.Builder;
6+
usingSystem.CommandLine.Parsing;
7+
usingSystem.IO;
8+
usingSystem.Threading.Tasks;
9+
namespaceMicrosoft.DotNet.Tools.Bootstrapper;
10+
11+
classProgram
512
{
6-
internalclassProgram
13+
staticintMain(string[]args)
714
{
8-
internalstaticintMain(string[]args)
9-
{
10-
return0;
11-
}
15+
returnBootstrapperCommandParser.BootstrapParser.InvokeAsync(args).Result;
1216
}
1317
}

‎test/dotnet-bootstrapper.Tests/EndToEndTests.cs

Lines changed: 2 additions & 1 deletion
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)

[8]ページ先頭

©2009-2025 Movatter.jp