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

68 lines
1.9 KiB
C#
Raw Normal View History

// 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;
using Microsoft.DotNet.Cli;
using System.Diagnostics;
2017-02-23 11:24:36 -08:00
using System;
using System.IO;
2017-02-01 16:11:12 -08:00
using System.Linq;
2017-03-09 16:17:15 -08:00
using Parser = Microsoft.DotNet.Cli.Parser;
namespace Microsoft.DotNet.Tools.Cache
{
2017-02-23 11:24:36 -08:00
public partial class CacheCommand : MSBuildForwardingApp
{
2017-02-23 11:24:36 -08:00
private CacheCommand(IEnumerable<string> msbuildArgs, string msbuildPath = null)
: base(msbuildArgs, msbuildPath)
{
}
public static CacheCommand FromArgs(string[] args, string msbuildPath = null)
{
2017-03-09 16:12:08 -08:00
var msbuildArgs = new List<string>();
var parser = Parser.Instance;
var result = parser.ParseFrom("dotnet cache", args);
result.ShowHelpIfRequested();
var appliedBuildOptions = result["dotnet"]["cache"];
2017-03-09 17:20:00 -08:00
if (!appliedBuildOptions.HasOption("-e"))
{
2017-03-09 16:12:08 -08:00
throw new InvalidOperationException(LocalizableStrings.SpecifyEntries);
}
2017-03-09 17:20:00 -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);
}
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();
}
}
}