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

Commit

Permalink
Changing the parser description for commands that have implicit restore.
Browse files Browse the repository at this point in the history
  • Loading branch information
livarcocc committed Jun 8, 2017
1 parent 3231295 commit c896186
Show file tree
Hide file tree
Showing 9 changed files with 224 additions and 256 deletions.
3 changes: 3 additions & 0 deletions src/dotnet/CommonLocalizableStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -520,4 +520,7 @@
<data name="ShowHelpDescription" xml:space="preserve">
<value>Show help information.</value>
</data>
<data name="NoRestoreDescription" xml:space="preserve">
<value>Does not do an implicit restore when executing the command.</value>
</data>
</root>
39 changes: 39 additions & 0 deletions src/dotnet/commands/CommandWithRestoreOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Collections.Generic;
using System.Linq;
using Microsoft.DotNet.Cli;
using Microsoft.DotNet.Cli.CommandLine;
using Microsoft.DotNet.Tools.MSBuild;
using Microsoft.DotNet.Tools.Restore;

namespace Microsoft.DotNet.Tools
{
public static class CreateWithRestoreOptions
{
public static Command Command(
string name,
string help,
ArgumentsRule arguments,
params Option[] options)
{
return Create.Command(name, help, arguments, RestoreCommandParser.AddImplicitRestoreOptions(options));
}

public static Command Command(
string name,
string help,
ArgumentsRule arguments,
bool treatUnmatchedTokensAsErrors,
params Option[] options)
{
return Create.Command(
name,
help,
arguments,
treatUnmatchedTokensAsErrors,
RestoreCommandParser.AddImplicitRestoreOptions(options));
}
}
}
27 changes: 12 additions & 15 deletions src/dotnet/commands/RestoringCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,20 @@ public class RestoringCommand : MSBuildForwardingApp

private IEnumerable<string> ArgsToForward { get; }

private IEnumerable<string> ArgsToForwardToRestore
private IEnumerable<string> ArgsToForwardToRestore()
{
get
{
var restoreArguments = ArgsToForward.Where(a =>
!a.StartsWith("/t:") &&
!a.StartsWith("/target:") &&
!a.StartsWith("/ConsoleLoggerParameters:") &&
!a.StartsWith("/clp:"));

if (!restoreArguments.Any(a => a.StartsWith("/v:") || a.StartsWith("/verbosity:")))
{
restoreArguments = restoreArguments.Concat(new string[] { "/v:q" });
}
var restoreArguments = ArgsToForward.Where(a =>
!a.StartsWith("/t:") &&
!a.StartsWith("/target:") &&
!a.StartsWith("/ConsoleLoggerParameters:") &&
!a.StartsWith("/clp:"));

return restoreArguments;
if (!restoreArguments.Any(a => a.StartsWith("/v:") || a.StartsWith("/verbosity:")))
{
restoreArguments = restoreArguments.Concat(new string[] { "/v:q" });
}

return restoreArguments;
}

private bool ShouldRunImplicitRestore => !NoRestore;
Expand All @@ -46,7 +43,7 @@ public override int Execute()
{
if (ShouldRunImplicitRestore)
{
int exitCode = RestoreCommand.Run(ArgsToForwardToRestore.ToArray());
int exitCode = RestoreCommand.Run(ArgsToForwardToRestore().ToArray());
if (exitCode != 0)
{
return exitCode;
Expand Down
60 changes: 22 additions & 38 deletions src/dotnet/commands/dotnet-build/BuildCommandParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,49 +12,33 @@ namespace Microsoft.DotNet.Cli
internal static class BuildCommandParser
{
public static Command Build() =>
Create.Command(
CreateWithRestoreOptions.Command(
"build",
LocalizableStrings.AppFullName,
Accept.ZeroOrMoreArguments()
.With(name: CommonLocalizableStrings.CmdProjectFile,
description:
"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."),
FullBuildOptions
);

private static Option[] FullBuildOptions
{
get
{
var fullBuildOptions = new List<Option>
{
CommonOptions.HelpOption(),
Create.Option(
"-o|--output",
LocalizableStrings.OutputOptionDescription,
Accept.ExactlyOneArgument()
.With(name: LocalizableStrings.OutputOptionName)
.ForwardAsSingle(o => $"/p:OutputPath={o.Arguments.Single()}")),
CommonOptions.FrameworkOption(),
CommonOptions.RuntimeOption(),
CommonOptions.ConfigurationOption(),
CommonOptions.VersionSuffixOption(),
Create.Option(
"--no-incremental",
LocalizableStrings.NoIncrementialOptionDescription),
Create.Option(
"--no-dependencies",
LocalizableStrings.NoDependenciesOptionDescription,
Accept.NoArguments()
.ForwardAs("/p:BuildProjectReferences=false")),
CommonOptions.NoRestoreOption(),
CommonOptions.VerbosityOption()
};

RestoreCommandParser.AddImplicitRestoreOptions(fullBuildOptions);

return fullBuildOptions.ToArray();
}
}
CommonOptions.HelpOption(),
Create.Option(
"-o|--output",
LocalizableStrings.OutputOptionDescription,
Accept.ExactlyOneArgument()
.With(name: LocalizableStrings.OutputOptionName)
.ForwardAsSingle(o => $"/p:OutputPath={o.Arguments.Single()}")),
CommonOptions.FrameworkOption(),
CommonOptions.RuntimeOption(),
CommonOptions.ConfigurationOption(),
CommonOptions.VersionSuffixOption(),
Create.Option(
"--no-incremental",
LocalizableStrings.NoIncrementialOptionDescription),
Create.Option(
"--no-dependencies",
LocalizableStrings.NoDependenciesOptionDescription,
Accept.NoArguments()
.ForwardAs("/p:BuildProjectReferences=false")),
CommonOptions.NoRestoreOption(),
CommonOptions.VerbosityOption());
}
}
72 changes: 29 additions & 43 deletions src/dotnet/commands/dotnet-pack/PackCommandParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,44 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.DotNet.Cli.CommandLine;
using Microsoft.DotNet.Tools;
using LocalizableStrings = Microsoft.DotNet.Tools.Pack.LocalizableStrings;

namespace Microsoft.DotNet.Cli
{
internal static class PackCommandParser
{
public static Command Pack() =>
Create.Command(
CreateWithRestoreOptions.Command(
"pack",
LocalizableStrings.AppFullName,
Accept.ZeroOrMoreArguments(),
FullPackOptions);

private static Option[] FullPackOptions
{
get
{
var fullPackOptions = new List<Option>
{
CommonOptions.HelpOption(),
Create.Option(
"-o|--output",
LocalizableStrings.CmdOutputDirDescription,
Accept.ExactlyOneArgument()
.With(name: LocalizableStrings.CmdOutputDir)
.ForwardAsSingle(o => $"/p:PackageOutputPath={o.Arguments.Single()}")),
Create.Option(
"--no-build",
LocalizableStrings.CmdNoBuildOptionDescription,
Accept.NoArguments().ForwardAs("/p:NoBuild=true")),
Create.Option(
"--include-symbols",
LocalizableStrings.CmdIncludeSymbolsDescription,
Accept.NoArguments().ForwardAs("/p:IncludeSymbols=true")),
Create.Option(
"--include-source",
LocalizableStrings.CmdIncludeSourceDescription,
Accept.NoArguments().ForwardAs("/p:IncludeSource=true")),
CommonOptions.ConfigurationOption(),
CommonOptions.VersionSuffixOption(),
Create.Option(
"-s|--serviceable",
LocalizableStrings.CmdServiceableDescription,
Accept.NoArguments().ForwardAs("/p:Serviceable=true")),
CommonOptions.NoRestoreOption(),
CommonOptions.VerbosityOption()
};

RestoreCommandParser.AddImplicitRestoreOptions(fullPackOptions);

return fullPackOptions.ToArray();
}
}
CommonOptions.HelpOption(),
Create.Option(
"-o|--output",
LocalizableStrings.CmdOutputDirDescription,
Accept.ExactlyOneArgument()
.With(name: LocalizableStrings.CmdOutputDir)
.ForwardAsSingle(o => $"/p:PackageOutputPath={o.Arguments.Single()}")),
Create.Option(
"--no-build",
LocalizableStrings.CmdNoBuildOptionDescription,
Accept.NoArguments().ForwardAs("/p:NoBuild=true")),
Create.Option(
"--include-symbols",
LocalizableStrings.CmdIncludeSymbolsDescription,
Accept.NoArguments().ForwardAs("/p:IncludeSymbols=true")),
Create.Option(
"--include-source",
LocalizableStrings.CmdIncludeSourceDescription,
Accept.NoArguments().ForwardAs("/p:IncludeSource=true")),
CommonOptions.ConfigurationOption(),
CommonOptions.VersionSuffixOption(),
Create.Option(
"-s|--serviceable",
LocalizableStrings.CmdServiceableDescription,
Accept.NoArguments().ForwardAs("/p:Serviceable=true")),
CommonOptions.NoRestoreOption(),
CommonOptions.VerbosityOption());
}
}
76 changes: 31 additions & 45 deletions src/dotnet/commands/dotnet-publish/PublishCommandParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,60 +4,46 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.DotNet.Cli.CommandLine;
using Microsoft.DotNet.Tools;
using LocalizableStrings = Microsoft.DotNet.Tools.Publish.LocalizableStrings;

namespace Microsoft.DotNet.Cli
{
internal static class PublishCommandParser
{
public static Command Publish() =>
Create.Command(
CreateWithRestoreOptions.Command(
"publish",
LocalizableStrings.AppDescription,
Accept.ZeroOrMoreArguments(),
FullPublishOptions);

private static Option[] FullPublishOptions
{
get
{
var fullPublishOptions = new List<Option>
{
CommonOptions.HelpOption(),
Create.Option(
"-o|--output",
LocalizableStrings.OutputOptionDescription,
Accept.ExactlyOneArgument()
.With(name: LocalizableStrings.OutputOption)
.ForwardAsSingle(o => $"/p:PublishDir={o.Arguments.Single()}")),
CommonOptions.FrameworkOption(),
CommonOptions.RuntimeOption(),
CommonOptions.ConfigurationOption(),
CommonOptions.VersionSuffixOption(),
Create.Option(
"--manifest",
LocalizableStrings.ManifestOptionDescription,
Accept.OneOrMoreArguments()
.With(name: LocalizableStrings.ManifestOption)
.ForwardAsSingle(o => $"/p:TargetManifestFiles={string.Join("%3B", o.Arguments)}")),
Create.Option(
"--self-contained",
LocalizableStrings.SelfContainedOptionDescription,
Accept.ZeroOrOneArgument()
.WithSuggestionsFrom("true", "false")
.ForwardAsSingle(o =>
{
string value = o.Arguments.Any() ? o.Arguments.Single() : "true";
return $"/p:SelfContained={value}";
})),
CommonOptions.NoRestoreOption(),
CommonOptions.VerbosityOption()
};

RestoreCommandParser.AddImplicitRestoreOptions(fullPublishOptions);

return fullPublishOptions.ToArray();
}
}
CommonOptions.HelpOption(),
Create.Option(
"-o|--output",
LocalizableStrings.OutputOptionDescription,
Accept.ExactlyOneArgument()
.With(name: LocalizableStrings.OutputOption)
.ForwardAsSingle(o => $"/p:PublishDir={o.Arguments.Single()}")),
CommonOptions.FrameworkOption(),
CommonOptions.RuntimeOption(),
CommonOptions.ConfigurationOption(),
CommonOptions.VersionSuffixOption(),
Create.Option(
"--manifest",
LocalizableStrings.ManifestOptionDescription,
Accept.OneOrMoreArguments()
.With(name: LocalizableStrings.ManifestOption)
.ForwardAsSingle(o => $"/p:TargetManifestFiles={string.Join("%3B", o.Arguments)}")),
Create.Option(
"--self-contained",
LocalizableStrings.SelfContainedOptionDescription,
Accept.ZeroOrOneArgument()
.WithSuggestionsFrom("true", "false")
.ForwardAsSingle(o =>
{
string value = o.Arguments.Any() ? o.Arguments.Single() : "true";
return $"/p:SelfContained={value}";
})),
CommonOptions.NoRestoreOption(),
CommonOptions.VerbosityOption());
}
}
Loading

0 comments on commit c896186

Please sign in to comment.