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

57 lines
2.2 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;
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
{
public partial class RunCommand
2015-10-30 15:40:13 -07:00
{
public static int Run(string[] args)
2015-10-30 15:40:13 -07:00
{
DebugHelper.HandleDebugSwitch(ref args);
CommandLineApplication app = new CommandLineApplication();
app.Name = "dotnet run";
app.FullName = ".NET Run Command";
app.Description = "Command used to run .NET apps";
app.HelpOption("-h|--help");
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);
// 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);
app.OnExecute(() =>
{
RunCommand runCmd = new RunCommand();
runCmd.Framework = framework.Value();
runCmd.Configuration = configuration.Value();
runCmd.Project = project.Value();
runCmd.Args = runArgs.Values;
2015-10-30 15:40:13 -07:00
return runCmd.Start();
});
2015-10-30 15:40:13 -07:00
try
{
return app.Execute(args);
2015-10-30 15:40:13 -07:00
}
catch (Exception ex)
{
#if DEBUG
Reporter.Error.WriteLine(ex.ToString());
2015-10-30 15:40:13 -07:00
#else
Reporter.Error.WriteLine(ex.Message);
2015-10-30 15:40:13 -07:00
#endif
return 1;
}
}
}
}