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-01-25 18:57:14 -08:00
|
|
|
|
|
|
|
|
|
namespace Microsoft.DotNet.Tools.Cache
|
|
|
|
|
{
|
|
|
|
|
public partial class CacheCommand
|
|
|
|
|
{
|
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);
|
|
|
|
|
|
|
|
|
|
var app = new CommandLineApplication(throwOnUnexpectedArg: false);
|
|
|
|
|
app.Name = "dotnet cache";
|
|
|
|
|
app.FullName = LocalizableStrings.AppFullName;
|
|
|
|
|
app.Description = LocalizableStrings.AppDescription;
|
|
|
|
|
app.AllowArgumentSeparator = true;
|
|
|
|
|
app.ArgumentSeparatorHelpText = HelpMessageStrings.MSBuildAdditionalArgsHelpText;
|
|
|
|
|
app.HelpOption("-h|--help");
|
|
|
|
|
|
|
|
|
|
CommandOption projectArgument = app.Option(
|
|
|
|
|
$"-e|--entries <{LocalizableStrings.ProjectEntries}>", LocalizableStrings.ProjectEntryDescription,
|
|
|
|
|
CommandOptionType.SingleValue);
|
|
|
|
|
|
|
|
|
|
CommandOption frameworkOption = app.Option(
|
|
|
|
|
$"-f|--framework <{LocalizableStrings.FrameworkOption}>", LocalizableStrings.FrameworkOptionDescription,
|
|
|
|
|
CommandOptionType.SingleValue);
|
|
|
|
|
|
|
|
|
|
CommandOption runtimeOption = app.Option(
|
|
|
|
|
$"-r|--runtime <{LocalizableStrings.RuntimeOption}>", LocalizableStrings.RuntimeOptionDescription,
|
|
|
|
|
CommandOptionType.SingleValue);
|
|
|
|
|
|
|
|
|
|
CommandOption outputOption = app.Option(
|
|
|
|
|
$"-o|--output <{LocalizableStrings.OutputOption}>", LocalizableStrings.OutputOptionDescription,
|
|
|
|
|
CommandOptionType.SingleValue);
|
|
|
|
|
|
|
|
|
|
CommandOption fxOption = app.Option(
|
|
|
|
|
$"--framework-version <{LocalizableStrings.FrameworkVersionOption}>", LocalizableStrings.FrameworkVersionOptionDescription,
|
|
|
|
|
CommandOptionType.SingleValue);
|
|
|
|
|
|
|
|
|
|
CommandOption skipOptimizationOption = app.Option(
|
|
|
|
|
$"--skip-optimization", LocalizableStrings.SkipOptimizationOptionDescription,
|
|
|
|
|
CommandOptionType.NoValue);
|
|
|
|
|
|
|
|
|
|
CommandOption workingDir = app.Option(
|
|
|
|
|
$"-w |--working-dir <{LocalizableStrings.IntermediateWorkingDirOption}>", LocalizableStrings.IntermediateWorkingDirOptionDescription,
|
|
|
|
|
CommandOptionType.SingleValue);
|
|
|
|
|
|
|
|
|
|
CommandOption preserveWorkingDir = app.Option(
|
|
|
|
|
$"--preserve-working-dir", LocalizableStrings.PreserveIntermediateWorkingDirOptionDescription,
|
|
|
|
|
CommandOptionType.NoValue);
|
|
|
|
|
|
|
|
|
|
CommandOption verbosityOption = MSBuildForwardingApp.AddVerbosityOption(app);
|
|
|
|
|
|
2017-02-22 15:49:39 -08:00
|
|
|
|
var cache = new CacheCommand(msbuildPath);
|
|
|
|
|
bool commandExecuted = false;
|
2017-01-25 18:57:14 -08:00
|
|
|
|
app.OnExecute(() =>
|
|
|
|
|
{
|
2017-02-22 15:49:39 -08:00
|
|
|
|
commandExecuted = true;
|
2017-01-25 18:57:14 -08:00
|
|
|
|
cache.Framework = frameworkOption.Value();
|
|
|
|
|
cache.Runtime = runtimeOption.Value();
|
|
|
|
|
cache.OutputPath = outputOption.Value();
|
|
|
|
|
cache.FrameworkVersion = fxOption.Value();
|
|
|
|
|
cache.Verbosity = verbosityOption.Value();
|
|
|
|
|
cache.SkipOptimization = skipOptimizationOption.HasValue();
|
|
|
|
|
cache.IntermediateDir = workingDir.Value();
|
|
|
|
|
cache.PreserveIntermediateDir = preserveWorkingDir.HasValue();
|
|
|
|
|
cache.ExtraMSBuildArguments = app.RemainingArguments;
|
|
|
|
|
cache.ProjectArgument = projectArgument.Value();
|
|
|
|
|
|
2017-02-22 15:49:39 -08:00
|
|
|
|
return 0;
|
2017-01-25 18:57:14 -08:00
|
|
|
|
});
|
|
|
|
|
|
2017-02-22 15:49:39 -08:00
|
|
|
|
int exitCode = app.Execute(args);
|
|
|
|
|
if (!commandExecuted)
|
|
|
|
|
{
|
|
|
|
|
throw new CommandCreationException(exitCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return cache;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ProcessStartInfo GetProcessStartInfo()
|
|
|
|
|
{
|
|
|
|
|
return CreateForwardingApp(_msbuildPath).GetProcessStartInfo();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int Execute()
|
|
|
|
|
{
|
|
|
|
|
return GetProcessStartInfo().Execute();
|
2017-01-25 18:57:14 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|