dotnet-installer/src/dotnet/commands/dotnet-restore/Program.cs
Livar Cunha 3231295acf Fixing a bug in the restore option where specifying verbosity through /v was not entirely honored.
Adding tests for implicit restore for all the affected commands.

Fixing an issue where the command target was being passed to the restore command during implicit restore.

Adding restore params to all commands with implicit restore. Also, implicitly set the restore output to quiet.

Adding tests for the no-restore option.
2017-06-07 17:41:30 -07:00

76 lines
No EOL
2.2 KiB
C#

// 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;
using System.Collections.Generic;
using System.Linq;
using Microsoft.DotNet.Cli.CommandLine;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Tools.MSBuild;
using Microsoft.DotNet.Cli;
using Parser = Microsoft.DotNet.Cli.Parser;
namespace Microsoft.DotNet.Tools.Restore
{
public class RestoreCommand : MSBuildForwardingApp
{
public RestoreCommand(IEnumerable<string> msbuildArgs, string msbuildPath = null)
: base(msbuildArgs, msbuildPath)
{
}
public static RestoreCommand FromArgs(string[] args, string msbuildPath = null)
{
DebugHelper.HandleDebugSwitch(ref args);
var parser = Parser.Instance;
var result = parser.ParseFrom("dotnet restore", args);
result.ShowHelpOrErrorIfAppropriate();
var parsedRestore = result["dotnet"]["restore"];
var msbuildArgs = new List<string>
{
"/NoLogo",
"/t:Restore"
};
if (!HasVerbosityOption(parsedRestore))
{
msbuildArgs.Add("/ConsoleLoggerParameters:Verbosity=Minimal");
}
msbuildArgs.AddRange(parsedRestore.OptionValuesToBeForwarded());
msbuildArgs.AddRange(parsedRestore.Arguments);
return new RestoreCommand(msbuildArgs, msbuildPath);
}
public static int Run(string[] args)
{
DebugHelper.HandleDebugSwitch(ref args);
RestoreCommand cmd;
try
{
cmd = FromArgs(args);
}
catch (CommandCreationException e)
{
return e.ExitCode;
}
return cmd.Execute();
}
private static bool HasVerbosityOption(AppliedOption parsedRestore)
{
return parsedRestore.HasOption("verbosity") ||
parsedRestore.Arguments.Any(a => a.Contains("/v:")) ||
parsedRestore.Arguments.Any(a => a.Contains("/verbosity:"));
}
}
}