2016-02-02 10:04:50 -08:00
using System.Collections.Generic ;
namespace Microsoft.DotNet.Cli.Build.Framework
{
public static class BuildHelpers
{
public static int ExecInSilent ( string workingDirectory , string command , params string [ ] args ) = > ExecInSilent ( workingDirectory , command , ( IEnumerable < string > ) args ) ;
2016-04-14 18:36:33 -07:00
public static int ExecInSilent ( string workingDirectory , string command , IEnumerable < string > args ) = > ExecCore ( command , args , workingDirectory , silent : true , env : null ) ;
2016-02-02 10:04:50 -08:00
public static int ExecIn ( string workingDirectory , string command , params string [ ] args ) = > ExecIn ( workingDirectory , command , ( IEnumerable < string > ) args ) ;
2016-04-14 18:36:33 -07:00
public static int ExecIn ( string workingDirectory , string command , IEnumerable < string > args ) = > ExecCore ( command , args , workingDirectory , silent : false , env : null ) ;
2016-02-02 10:04:50 -08:00
public static int ExecSilent ( string command , params string [ ] args ) = > ExecSilent ( command , ( IEnumerable < string > ) args ) ;
2016-04-14 18:36:33 -07:00
public static int ExecSilent ( string command , IEnumerable < string > args ) = > ExecSilent ( command , args , env : null ) ;
2016-06-06 10:31:44 -05:00
public static int ExecSilent ( string command , IEnumerable < string > args , IDictionary < string , string > env ) = > ExecCore ( command , args , workingDirectory : null , silent : true , env : env ) ;
2016-02-02 10:04:50 -08:00
public static int Exec ( string command , params string [ ] args ) = > Exec ( command , ( IEnumerable < string > ) args ) ;
2016-04-14 18:36:33 -07:00
public static int Exec ( string command , IEnumerable < string > args ) = > ExecCore ( command , args , workingDirectory : null , silent : false , env : null ) ;
2016-02-02 10:04:50 -08:00
public static Command Cmd ( string command , params string [ ] args ) = > Cmd ( command , ( IEnumerable < string > ) args ) ;
public static Command Cmd ( string command , IEnumerable < string > args )
{
return Command . Create ( command , args ) ;
}
2016-04-14 18:36:33 -07:00
internal static int ExecCore ( string command , IEnumerable < string > args , string workingDirectory , bool silent , IDictionary < string , string > env )
2016-02-02 10:04:50 -08:00
{
var cmd = Cmd ( command , args ) ;
2016-04-14 18:36:33 -07:00
if ( ! string . IsNullOrEmpty ( workingDirectory ) )
2016-02-02 10:04:50 -08:00
{
cmd . WorkingDirectory ( workingDirectory ) ;
}
2016-04-14 18:36:33 -07:00
if ( silent )
2016-02-02 10:04:50 -08:00
{
cmd . CaptureStdErr ( ) . CaptureStdOut ( ) ;
}
2016-04-14 18:36:33 -07:00
var result = cmd . Environment ( env ) . Execute ( ) ;
2016-02-02 10:04:50 -08:00
result . EnsureSuccessful ( ) ;
return result . ExitCode ;
}
2016-04-14 18:36:33 -07:00
2016-02-02 10:04:50 -08:00
}
}