2016-01-04 12:36:46 -08:00
|
|
|
// 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.
|
|
|
|
|
2017-03-07 11:28:35 -08:00
|
|
|
using System;
|
2016-10-27 18:46:43 -07:00
|
|
|
using System.Collections.Generic;
|
2017-03-08 16:02:24 -08:00
|
|
|
using System.Linq;
|
2016-04-19 22:51:32 -05:00
|
|
|
using Microsoft.DotNet.Cli.CommandLine;
|
2016-01-04 12:36:46 -08:00
|
|
|
using Microsoft.DotNet.Cli.Utils;
|
2016-10-27 18:46:43 -07:00
|
|
|
using Microsoft.DotNet.Tools.MSBuild;
|
2017-02-22 11:43:03 -08:00
|
|
|
using Microsoft.DotNet.Cli;
|
2017-03-06 20:53:26 -08:00
|
|
|
using Parser = Microsoft.DotNet.Cli.Parser;
|
2016-01-04 12:36:46 -08:00
|
|
|
|
|
|
|
namespace Microsoft.DotNet.Tools.Restore
|
|
|
|
{
|
2017-02-23 11:31:48 -08:00
|
|
|
public class RestoreCommand : MSBuildForwardingApp
|
2016-01-04 12:36:46 -08:00
|
|
|
{
|
2017-02-22 11:43:03 -08:00
|
|
|
public RestoreCommand(IEnumerable<string> msbuildArgs, string msbuildPath = null)
|
2017-02-23 11:31:48 -08:00
|
|
|
: base(msbuildArgs, msbuildPath)
|
2017-02-22 11:43:03 -08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-10-24 15:04:24 -07:00
|
|
|
public static RestoreCommand FromArgs(string[] args, string msbuildPath = null, bool noLogo = true)
|
2016-01-04 12:36:46 -08:00
|
|
|
{
|
|
|
|
DebugHelper.HandleDebugSwitch(ref args);
|
|
|
|
|
2017-03-08 16:02:24 -08:00
|
|
|
var parser = Parser.Instance;
|
2016-10-27 18:46:43 -07:00
|
|
|
|
2017-03-08 16:02:24 -08:00
|
|
|
var result = parser.ParseFrom("dotnet restore", args);
|
2016-10-27 18:46:43 -07:00
|
|
|
|
2017-03-13 13:29:03 -07:00
|
|
|
result.ShowHelpOrErrorIfAppropriate();
|
2017-03-09 13:57:37 -08:00
|
|
|
|
2017-03-10 13:49:49 -08:00
|
|
|
var parsedRestore = result["dotnet"]["restore"];
|
2016-10-27 18:46:43 -07:00
|
|
|
|
2017-10-24 15:50:43 -07:00
|
|
|
var msbuildArgs = new List<string>();
|
|
|
|
|
|
|
|
if (noLogo)
|
2016-10-27 18:46:43 -07:00
|
|
|
{
|
2018-04-02 14:44:43 -07:00
|
|
|
msbuildArgs.Add("-nologo");
|
2017-10-24 15:50:43 -07:00
|
|
|
}
|
|
|
|
|
2018-04-02 15:14:32 -07:00
|
|
|
msbuildArgs.Add("-target:Restore");
|
2016-10-27 18:46:43 -07:00
|
|
|
|
2017-03-10 13:49:49 -08:00
|
|
|
msbuildArgs.AddRange(parsedRestore.OptionValuesToBeForwarded());
|
2017-02-22 11:43:03 -08:00
|
|
|
|
2017-03-10 13:49:49 -08:00
|
|
|
msbuildArgs.AddRange(parsedRestore.Arguments);
|
2017-06-02 23:32:53 -07:00
|
|
|
|
2017-02-22 11:43:03 -08:00
|
|
|
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;
|
|
|
|
}
|
2017-03-09 12:31:34 -08:00
|
|
|
|
2017-02-22 11:43:03 -08:00
|
|
|
return cmd.Execute();
|
|
|
|
}
|
2016-01-04 12:36:46 -08:00
|
|
|
}
|
2017-03-06 20:53:26 -08:00
|
|
|
}
|