2017-01-25 18:57:14 -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.Collections.Generic;
|
|
|
|
|
using Microsoft.DotNet.Cli.CommandLine;
|
|
|
|
|
using Microsoft.DotNet.Cli.Utils;
|
|
|
|
|
using Microsoft.DotNet.Tools.MSBuild;
|
2017-02-22 15:49:39 -08:00
|
|
|
|
using Microsoft.DotNet.Cli;
|
|
|
|
|
using System.Diagnostics;
|
2017-02-23 11:24:36 -08:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
2017-03-09 16:17:15 -08:00
|
|
|
|
using Parser = Microsoft.DotNet.Cli.Parser;
|
2017-01-25 18:57:14 -08:00
|
|
|
|
|
|
|
|
|
namespace Microsoft.DotNet.Tools.Cache
|
|
|
|
|
{
|
2017-02-23 11:24:36 -08:00
|
|
|
|
public partial class CacheCommand : MSBuildForwardingApp
|
2017-01-25 18:57:14 -08:00
|
|
|
|
{
|
2017-02-23 11:24:36 -08:00
|
|
|
|
private CacheCommand(IEnumerable<string> msbuildArgs, string msbuildPath = null)
|
|
|
|
|
: base(msbuildArgs, msbuildPath)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-22 15:49:39 -08:00
|
|
|
|
public static CacheCommand FromArgs(string[] args, string msbuildPath = null)
|
2017-01-25 18:57:14 -08:00
|
|
|
|
{
|
|
|
|
|
DebugHelper.HandleDebugSwitch(ref args);
|
|
|
|
|
|
2017-03-09 16:12:08 -08:00
|
|
|
|
var msbuildArgs = new List<string>();
|
|
|
|
|
|
|
|
|
|
var parser = Parser.Instance;
|
|
|
|
|
|
|
|
|
|
var result = parser.ParseFrom("dotnet cache", args);
|
|
|
|
|
|
|
|
|
|
Reporter.Output.WriteLine(result.Diagram());
|
|
|
|
|
|
|
|
|
|
result.ShowHelpIfRequested();
|
|
|
|
|
|
|
|
|
|
var appliedBuildOptions = result["dotnet"]["cache"];
|
|
|
|
|
|
|
|
|
|
if (!result.HasOption("-e"))
|
2017-02-22 15:49:39 -08:00
|
|
|
|
{
|
2017-03-09 16:12:08 -08:00
|
|
|
|
throw new InvalidOperationException(LocalizableStrings.SpecifyEntries);
|
2017-02-22 15:49:39 -08:00
|
|
|
|
}
|
2017-03-09 16:17:15 -08:00
|
|
|
|
|
2017-03-09 16:12:08 -08:00
|
|
|
|
msbuildArgs.Add("/t:ComposeCache");
|
|
|
|
|
|
|
|
|
|
msbuildArgs.AddRange(appliedBuildOptions.OptionValuesToBeForwarded());
|
|
|
|
|
|
|
|
|
|
msbuildArgs.AddRange(appliedBuildOptions.Arguments);
|
|
|
|
|
|
2017-02-23 11:24:36 -08:00
|
|
|
|
return new CacheCommand(msbuildArgs, msbuildPath);
|
2017-02-22 15:49:39 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static int Run(string[] args)
|
|
|
|
|
{
|
|
|
|
|
DebugHelper.HandleDebugSwitch(ref args);
|
|
|
|
|
|
|
|
|
|
CacheCommand cmd;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
cmd = FromArgs(args);
|
|
|
|
|
}
|
|
|
|
|
catch (CommandCreationException e)
|
|
|
|
|
{
|
|
|
|
|
return e.ExitCode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return cmd.Execute();
|
|
|
|
|
}
|
2017-01-25 18:57:14 -08:00
|
|
|
|
}
|
|
|
|
|
}
|