dotnet-installer/src/dotnet/commands/dotnet-restore/Program.cs

67 lines
1.8 KiB
C#
Raw Normal View History

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.
using System;
using System.Collections.Generic;
2017-03-08 16:02:24 -08:00
using System.Linq;
using Microsoft.DotNet.Cli.CommandLine;
2016-01-04 12:36:46 -08:00
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Tools.MSBuild;
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
{
public RestoreCommand(IEnumerable<string> msbuildArgs, string msbuildPath = null)
2017-02-23 11:31:48 -08:00
: base(msbuildArgs, msbuildPath)
{
}
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;
2017-03-08 16:02:24 -08:00
var result = parser.ParseFrom("dotnet restore", args);
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"];
var msbuildArgs = new List<string>();
if (noLogo)
{
msbuildArgs.Add("-nologo");
}
msbuildArgs.Add("-target:Restore");
2017-03-10 13:49:49 -08:00
msbuildArgs.AddRange(parsedRestore.OptionValuesToBeForwarded());
2017-03-10 13:49:49 -08:00
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();
}
2016-01-04 12:36:46 -08:00
}
2017-03-06 20:53:26 -08:00
}