2017-03-03 05:04:03 +00: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 ;
2016-03-28 09:32:31 +00:00
using System.IO ;
using System.Collections.Generic ;
using System.Linq ;
using Microsoft.DotNet.Cli.Utils ;
2016-10-14 04:42:19 +00:00
using NuGet.Frameworks ;
2016-03-28 09:32:31 +00:00
namespace Microsoft.DotNet.Tools.DependencyInvoker
{
public class Program
{
2016-05-08 21:20:34 +00:00
public static int Main ( string [ ] args )
2016-03-28 09:32:31 +00:00
{
DebugHelper . HandleDebugSwitch ( ref args ) ;
var dotnetParams = new DotnetBaseParams ( "dotnet-dependency-tool-invoker" , "DotNet Dependency Tool Invoker" , "Invokes tools declared as NuGet dependencies of a project" ) ;
2017-03-03 05:04:03 +00:00
2016-03-28 09:32:31 +00:00
dotnetParams . Parse ( args ) ;
2017-03-03 05:04:03 +00:00
2016-03-28 09:32:31 +00:00
if ( string . IsNullOrEmpty ( dotnetParams . Command ) )
{
Console . WriteLine ( "A command name must be provided" ) ;
2017-03-03 05:04:03 +00:00
2016-05-08 21:20:34 +00:00
return 1 ;
2016-03-28 09:32:31 +00:00
}
2016-10-28 01:46:43 +00:00
2016-03-28 09:32:31 +00:00
var commandFactory =
new ProjectDependenciesCommandFactory (
dotnetParams . Framework ,
dotnetParams . Config ,
dotnetParams . Output ,
dotnetParams . BuildBasePath ,
2016-10-14 04:42:19 +00:00
dotnetParams . ProjectPath ) ;
2016-10-28 01:46:43 +00:00
var result = InvokeDependencyToolForMSBuild ( commandFactory , dotnetParams ) ;
2016-10-14 04:42:19 +00:00
return result ;
}
private static int InvokeDependencyToolForMSBuild (
ProjectDependenciesCommandFactory commandFactory ,
DotnetBaseParams dotnetParams )
{
Console . WriteLine ( $"Invoking '{dotnetParams.Command}' for '{dotnetParams.Framework.GetShortFolderName()}'." ) ;
return InvokeDependencyTool ( commandFactory , dotnetParams , dotnetParams . Framework ) ;
}
private static int InvokeDependencyTool (
ProjectDependenciesCommandFactory commandFactory ,
DotnetBaseParams dotnetParams ,
NuGetFramework framework )
{
try
{
var exitCode = commandFactory . Create (
$"dotnet-{dotnetParams.Command}" ,
dotnetParams . RemainingArguments ,
framework ,
dotnetParams . Config )
. ForwardStdErr ( )
. ForwardStdOut ( )
. Execute ( )
. ExitCode ;
Console . WriteLine ( $"Command returned {exitCode}" ) ;
}
catch ( CommandUnknownException )
{
Console . WriteLine ( $"Command not found" ) ;
return 1 ;
}
2016-05-08 21:20:34 +00:00
return 0 ;
2016-03-28 09:32:31 +00:00
}
}
}