Skip to content
This repository was archived by the owner on Apr 20, 2023. It is now read-only.

Commit c896186

Browse files
committed
Changing the parser description for commands that have implicit restore.
1 parent 3231295 commit c896186

File tree

9 files changed

+224
-256
lines changed

9 files changed

+224
-256
lines changed

src/dotnet/CommonLocalizableStrings.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,4 +520,7 @@
520520
<data name="ShowHelpDescription" xml:space="preserve">
521521
<value>Show help information.</value>
522522
</data>
523+
<data name="NoRestoreDescription" xml:space="preserve">
524+
<value>Does not do an implicit restore when executing the command.</value>
525+
</data>
523526
</root>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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.Collections.Generic;
5+
using System.Linq;
6+
using Microsoft.DotNet.Cli;
7+
using Microsoft.DotNet.Cli.CommandLine;
8+
using Microsoft.DotNet.Tools.MSBuild;
9+
using Microsoft.DotNet.Tools.Restore;
10+
11+
namespace Microsoft.DotNet.Tools
12+
{
13+
public static class CreateWithRestoreOptions
14+
{
15+
public static Command Command(
16+
string name,
17+
string help,
18+
ArgumentsRule arguments,
19+
params Option[] options)
20+
{
21+
return Create.Command(name, help, arguments, RestoreCommandParser.AddImplicitRestoreOptions(options));
22+
}
23+
24+
public static Command Command(
25+
string name,
26+
string help,
27+
ArgumentsRule arguments,
28+
bool treatUnmatchedTokensAsErrors,
29+
params Option[] options)
30+
{
31+
return Create.Command(
32+
name,
33+
help,
34+
arguments,
35+
treatUnmatchedTokensAsErrors,
36+
RestoreCommandParser.AddImplicitRestoreOptions(options));
37+
}
38+
}
39+
}

src/dotnet/commands/RestoringCommand.cs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,20 @@ public class RestoringCommand : MSBuildForwardingApp
1414

1515
private IEnumerable<string> ArgsToForward { get; }
1616

17-
private IEnumerable<string> ArgsToForwardToRestore
17+
private IEnumerable<string> ArgsToForwardToRestore()
1818
{
19-
get
20-
{
21-
var restoreArguments = ArgsToForward.Where(a =>
22-
!a.StartsWith("/t:") &&
23-
!a.StartsWith("/target:") &&
24-
!a.StartsWith("/ConsoleLoggerParameters:") &&
25-
!a.StartsWith("/clp:"));
26-
27-
if (!restoreArguments.Any(a => a.StartsWith("/v:") || a.StartsWith("/verbosity:")))
28-
{
29-
restoreArguments = restoreArguments.Concat(new string[] { "/v:q" });
30-
}
19+
var restoreArguments = ArgsToForward.Where(a =>
20+
!a.StartsWith("/t:") &&
21+
!a.StartsWith("/target:") &&
22+
!a.StartsWith("/ConsoleLoggerParameters:") &&
23+
!a.StartsWith("/clp:"));
3124

32-
return restoreArguments;
25+
if (!restoreArguments.Any(a => a.StartsWith("/v:") || a.StartsWith("/verbosity:")))
26+
{
27+
restoreArguments = restoreArguments.Concat(new string[] { "/v:q" });
3328
}
29+
30+
return restoreArguments;
3431
}
3532

3633
private bool ShouldRunImplicitRestore => !NoRestore;
@@ -46,7 +43,7 @@ public override int Execute()
4643
{
4744
if (ShouldRunImplicitRestore)
4845
{
49-
int exitCode = RestoreCommand.Run(ArgsToForwardToRestore.ToArray());
46+
int exitCode = RestoreCommand.Run(ArgsToForwardToRestore().ToArray());
5047
if (exitCode != 0)
5148
{
5249
return exitCode;

src/dotnet/commands/dotnet-build/BuildCommandParser.cs

Lines changed: 22 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,49 +12,33 @@ namespace Microsoft.DotNet.Cli
1212
internal static class BuildCommandParser
1313
{
1414
public static Command Build() =>
15-
Create.Command(
15+
CreateWithRestoreOptions.Command(
1616
"build",
1717
LocalizableStrings.AppFullName,
1818
Accept.ZeroOrMoreArguments()
1919
.With(name: CommonLocalizableStrings.CmdProjectFile,
2020
description:
2121
"The MSBuild project file to build. If a project file is not specified, MSBuild searches the current working directory for a file that has a file extension that ends in `proj` and uses that file."),
22-
FullBuildOptions
23-
);
24-
25-
private static Option[] FullBuildOptions
26-
{
27-
get
28-
{
29-
var fullBuildOptions = new List<Option>
30-
{
31-
CommonOptions.HelpOption(),
32-
Create.Option(
33-
"-o|--output",
34-
LocalizableStrings.OutputOptionDescription,
35-
Accept.ExactlyOneArgument()
36-
.With(name: LocalizableStrings.OutputOptionName)
37-
.ForwardAsSingle(o => $"/p:OutputPath={o.Arguments.Single()}")),
38-
CommonOptions.FrameworkOption(),
39-
CommonOptions.RuntimeOption(),
40-
CommonOptions.ConfigurationOption(),
41-
CommonOptions.VersionSuffixOption(),
42-
Create.Option(
43-
"--no-incremental",
44-
LocalizableStrings.NoIncrementialOptionDescription),
45-
Create.Option(
46-
"--no-dependencies",
47-
LocalizableStrings.NoDependenciesOptionDescription,
48-
Accept.NoArguments()
49-
.ForwardAs("/p:BuildProjectReferences=false")),
50-
CommonOptions.NoRestoreOption(),
51-
CommonOptions.VerbosityOption()
52-
};
53-
54-
RestoreCommandParser.AddImplicitRestoreOptions(fullBuildOptions);
55-
56-
return fullBuildOptions.ToArray();
57-
}
58-
}
22+
CommonOptions.HelpOption(),
23+
Create.Option(
24+
"-o|--output",
25+
LocalizableStrings.OutputOptionDescription,
26+
Accept.ExactlyOneArgument()
27+
.With(name: LocalizableStrings.OutputOptionName)
28+
.ForwardAsSingle(o => $"/p:OutputPath={o.Arguments.Single()}")),
29+
CommonOptions.FrameworkOption(),
30+
CommonOptions.RuntimeOption(),
31+
CommonOptions.ConfigurationOption(),
32+
CommonOptions.VersionSuffixOption(),
33+
Create.Option(
34+
"--no-incremental",
35+
LocalizableStrings.NoIncrementialOptionDescription),
36+
Create.Option(
37+
"--no-dependencies",
38+
LocalizableStrings.NoDependenciesOptionDescription,
39+
Accept.NoArguments()
40+
.ForwardAs("/p:BuildProjectReferences=false")),
41+
CommonOptions.NoRestoreOption(),
42+
CommonOptions.VerbosityOption());
5943
}
6044
}

src/dotnet/commands/dotnet-pack/PackCommandParser.cs

Lines changed: 29 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,58 +4,44 @@
44
using System.Collections.Generic;
55
using System.Linq;
66
using Microsoft.DotNet.Cli.CommandLine;
7+
using Microsoft.DotNet.Tools;
78
using LocalizableStrings = Microsoft.DotNet.Tools.Pack.LocalizableStrings;
89

910
namespace Microsoft.DotNet.Cli
1011
{
1112
internal static class PackCommandParser
1213
{
1314
public static Command Pack() =>
14-
Create.Command(
15+
CreateWithRestoreOptions.Command(
1516
"pack",
1617
LocalizableStrings.AppFullName,
1718
Accept.ZeroOrMoreArguments(),
18-
FullPackOptions);
19-
20-
private static Option[] FullPackOptions
21-
{
22-
get
23-
{
24-
var fullPackOptions = new List<Option>
25-
{
26-
CommonOptions.HelpOption(),
27-
Create.Option(
28-
"-o|--output",
29-
LocalizableStrings.CmdOutputDirDescription,
30-
Accept.ExactlyOneArgument()
31-
.With(name: LocalizableStrings.CmdOutputDir)
32-
.ForwardAsSingle(o => $"/p:PackageOutputPath={o.Arguments.Single()}")),
33-
Create.Option(
34-
"--no-build",
35-
LocalizableStrings.CmdNoBuildOptionDescription,
36-
Accept.NoArguments().ForwardAs("/p:NoBuild=true")),
37-
Create.Option(
38-
"--include-symbols",
39-
LocalizableStrings.CmdIncludeSymbolsDescription,
40-
Accept.NoArguments().ForwardAs("/p:IncludeSymbols=true")),
41-
Create.Option(
42-
"--include-source",
43-
LocalizableStrings.CmdIncludeSourceDescription,
44-
Accept.NoArguments().ForwardAs("/p:IncludeSource=true")),
45-
CommonOptions.ConfigurationOption(),
46-
CommonOptions.VersionSuffixOption(),
47-
Create.Option(
48-
"-s|--serviceable",
49-
LocalizableStrings.CmdServiceableDescription,
50-
Accept.NoArguments().ForwardAs("/p:Serviceable=true")),
51-
CommonOptions.NoRestoreOption(),
52-
CommonOptions.VerbosityOption()
53-
};
54-
55-
RestoreCommandParser.AddImplicitRestoreOptions(fullPackOptions);
56-
57-
return fullPackOptions.ToArray();
58-
}
59-
}
19+
CommonOptions.HelpOption(),
20+
Create.Option(
21+
"-o|--output",
22+
LocalizableStrings.CmdOutputDirDescription,
23+
Accept.ExactlyOneArgument()
24+
.With(name: LocalizableStrings.CmdOutputDir)
25+
.ForwardAsSingle(o => $"/p:PackageOutputPath={o.Arguments.Single()}")),
26+
Create.Option(
27+
"--no-build",
28+
LocalizableStrings.CmdNoBuildOptionDescription,
29+
Accept.NoArguments().ForwardAs("/p:NoBuild=true")),
30+
Create.Option(
31+
"--include-symbols",
32+
LocalizableStrings.CmdIncludeSymbolsDescription,
33+
Accept.NoArguments().ForwardAs("/p:IncludeSymbols=true")),
34+
Create.Option(
35+
"--include-source",
36+
LocalizableStrings.CmdIncludeSourceDescription,
37+
Accept.NoArguments().ForwardAs("/p:IncludeSource=true")),
38+
CommonOptions.ConfigurationOption(),
39+
CommonOptions.VersionSuffixOption(),
40+
Create.Option(
41+
"-s|--serviceable",
42+
LocalizableStrings.CmdServiceableDescription,
43+
Accept.NoArguments().ForwardAs("/p:Serviceable=true")),
44+
CommonOptions.NoRestoreOption(),
45+
CommonOptions.VerbosityOption());
6046
}
6147
}

src/dotnet/commands/dotnet-publish/PublishCommandParser.cs

Lines changed: 31 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,60 +4,46 @@
44
using System.Collections.Generic;
55
using System.Linq;
66
using Microsoft.DotNet.Cli.CommandLine;
7+
using Microsoft.DotNet.Tools;
78
using LocalizableStrings = Microsoft.DotNet.Tools.Publish.LocalizableStrings;
89

910
namespace Microsoft.DotNet.Cli
1011
{
1112
internal static class PublishCommandParser
1213
{
1314
public static Command Publish() =>
14-
Create.Command(
15+
CreateWithRestoreOptions.Command(
1516
"publish",
1617
LocalizableStrings.AppDescription,
1718
Accept.ZeroOrMoreArguments(),
18-
FullPublishOptions);
19-
20-
private static Option[] FullPublishOptions
21-
{
22-
get
23-
{
24-
var fullPublishOptions = new List<Option>
25-
{
26-
CommonOptions.HelpOption(),
27-
Create.Option(
28-
"-o|--output",
29-
LocalizableStrings.OutputOptionDescription,
30-
Accept.ExactlyOneArgument()
31-
.With(name: LocalizableStrings.OutputOption)
32-
.ForwardAsSingle(o => $"/p:PublishDir={o.Arguments.Single()}")),
33-
CommonOptions.FrameworkOption(),
34-
CommonOptions.RuntimeOption(),
35-
CommonOptions.ConfigurationOption(),
36-
CommonOptions.VersionSuffixOption(),
37-
Create.Option(
38-
"--manifest",
39-
LocalizableStrings.ManifestOptionDescription,
40-
Accept.OneOrMoreArguments()
41-
.With(name: LocalizableStrings.ManifestOption)
42-
.ForwardAsSingle(o => $"/p:TargetManifestFiles={string.Join("%3B", o.Arguments)}")),
43-
Create.Option(
44-
"--self-contained",
45-
LocalizableStrings.SelfContainedOptionDescription,
46-
Accept.ZeroOrOneArgument()
47-
.WithSuggestionsFrom("true", "false")
48-
.ForwardAsSingle(o =>
49-
{
50-
string value = o.Arguments.Any() ? o.Arguments.Single() : "true";
51-
return $"/p:SelfContained={value}";
52-
})),
53-
CommonOptions.NoRestoreOption(),
54-
CommonOptions.VerbosityOption()
55-
};
56-
57-
RestoreCommandParser.AddImplicitRestoreOptions(fullPublishOptions);
58-
59-
return fullPublishOptions.ToArray();
60-
}
61-
}
19+
CommonOptions.HelpOption(),
20+
Create.Option(
21+
"-o|--output",
22+
LocalizableStrings.OutputOptionDescription,
23+
Accept.ExactlyOneArgument()
24+
.With(name: LocalizableStrings.OutputOption)
25+
.ForwardAsSingle(o => $"/p:PublishDir={o.Arguments.Single()}")),
26+
CommonOptions.FrameworkOption(),
27+
CommonOptions.RuntimeOption(),
28+
CommonOptions.ConfigurationOption(),
29+
CommonOptions.VersionSuffixOption(),
30+
Create.Option(
31+
"--manifest",
32+
LocalizableStrings.ManifestOptionDescription,
33+
Accept.OneOrMoreArguments()
34+
.With(name: LocalizableStrings.ManifestOption)
35+
.ForwardAsSingle(o => $"/p:TargetManifestFiles={string.Join("%3B", o.Arguments)}")),
36+
Create.Option(
37+
"--self-contained",
38+
LocalizableStrings.SelfContainedOptionDescription,
39+
Accept.ZeroOrOneArgument()
40+
.WithSuggestionsFrom("true", "false")
41+
.ForwardAsSingle(o =>
42+
{
43+
string value = o.Arguments.Any() ? o.Arguments.Single() : "true";
44+
return $"/p:SelfContained={value}";
45+
})),
46+
CommonOptions.NoRestoreOption(),
47+
CommonOptions.VerbosityOption());
6248
}
6349
}

0 commit comments

Comments
 (0)