2015-11-16 11:21:57 -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.
2015-11-20 19:00:56 -08:00
using System ;
2016-04-19 22:51:32 -05:00
using Microsoft.DotNet.Cli.CommandLine ;
using Microsoft.DotNet.Cli.Utils ;
2015-10-30 15:40:13 -07:00
2015-11-01 02:46:05 -08:00
namespace Microsoft.DotNet.Tools.Run
2015-10-30 15:40:13 -07:00
{
2016-01-30 21:47:50 -08:00
public partial class RunCommand
2015-10-30 15:40:13 -07:00
{
2016-01-30 21:47:50 -08:00
public static int Run ( string [ ] args )
2015-10-30 15:40:13 -07:00
{
DebugHelper . HandleDebugSwitch ( ref args ) ;
2016-04-19 22:51:32 -05:00
CommandLineApplication app = new CommandLineApplication ( ) ;
app . Name = "dotnet run" ;
app . FullName = ".NET Run Command" ;
app . Description = "Command used to run .NET apps" ;
2016-04-20 00:28:34 -05:00
app . HandleResponseFiles = true ;
2016-04-19 22:51:32 -05:00
app . HelpOption ( "-h|--help" ) ;
2015-12-18 10:30:04 -08:00
2016-04-19 22:51:32 -05:00
CommandOption framework = app . Option ( "-f|--framework" , "Compile a specific framework" , CommandOptionType . SingleValue ) ;
CommandOption configuration = app . Option ( "-c|--configuration" , "Configuration under which to build" , CommandOptionType . SingleValue ) ;
CommandOption project = app . Option ( "-p|--project" , "The path to the project to run (defaults to the current directory). Can be a path to a project.json or a project directory" , CommandOptionType . SingleValue ) ;
2015-12-18 10:30:04 -08:00
2016-04-19 22:51:32 -05:00
// TODO: this is not supporting args which can be switches (i.e. --test)
// TODO: we need to make a change in CommandLine utils or parse args ourselves.
CommandArgument runArgs = app . Argument ( "args" , "Arguments to pass to the executable or script" , multipleValues : true ) ;
2015-12-18 10:30:04 -08:00
2016-04-19 22:51:32 -05:00
app . OnExecute ( ( ) = >
2015-12-18 10:30:04 -08:00
{
2016-04-19 22:51:32 -05:00
RunCommand runCmd = new RunCommand ( ) ;
2015-12-18 10:30:04 -08:00
2016-04-19 22:51:32 -05:00
runCmd . Framework = framework . Value ( ) ;
runCmd . Configuration = configuration . Value ( ) ;
runCmd . Project = project . Value ( ) ;
runCmd . Args = runArgs . Values ;
2015-10-30 15:40:13 -07:00
2016-04-19 22:51:32 -05:00
return runCmd . Start ( ) ;
} ) ;
2016-04-20 00:28:34 -05:00
2015-10-30 15:40:13 -07:00
try
{
2016-04-19 22:51:32 -05:00
return app . Execute ( args ) ;
2015-10-30 15:40:13 -07:00
}
catch ( Exception ex )
{
#if DEBUG
2016-04-19 22:51:32 -05:00
Reporter . Error . WriteLine ( ex . ToString ( ) ) ;
2015-10-30 15:40:13 -07:00
#else
2016-04-19 22:51:32 -05:00
Reporter . Error . WriteLine ( ex . Message ) ;
2015-10-30 15:40:13 -07:00
#endif
return 1 ;
}
}
}
}