// 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; using System; using System.IO; namespace Microsoft.DotNet.Tools.Cache { public partial class CacheCommand : MSBuildForwardingApp { private CacheCommand(IEnumerable msbuildArgs, string msbuildPath = null) : base(msbuildArgs, msbuildPath) { } public static CacheCommand FromArgs(string[] args, string msbuildPath = null) { DebugHelper.HandleDebugSwitch(ref args); var msbuildArgs = new List(); 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")) { throw new InvalidOperationException(LocalizableStrings.SpecifyEntries); } var msbuildArgs = msbuildArgs = new List(); msbuildArgs.Add("/t:ComposeCache"); msbuildArgs.AddRange(appliedBuildOptions.OptionValuesToBeForwarded()); msbuildArgs.AddRange(appliedBuildOptions.Arguments); 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(); } } }