public static int Main(string[] args) { DebugHelper.HandleDebugSwitch(ref args); RunCommand runCmd = new RunCommand(); ArgumentSyntax.Parse(args, syntax => { syntax.HandleErrors = false; syntax.DefineOption("f|framework", ref runCmd.Framework, "Compile a specific framework"); syntax.DefineOption("c|configuration", ref runCmd.Configuration, "Configuration under which to build"); syntax.DefineOption("t|preserve-temporary", ref runCmd.PreserveTemporary, "Keep the output's temporary directory around"); syntax.DefineOption("p|project", ref runCmd.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"); // TODO: this is not supporting args which can be switches (i.e. --test) // TODO: we need to make a change in System.CommandLine or parse args ourselves. syntax.DefineParameterList("args", ref runCmd.Args, "Arguments to pass to the executable or script"); }); try { return runCmd.Start(); } catch (Exception ex) { #if DEBUG Console.Error.WriteLine(ex); #else Console.Error.WriteLine(ex.Message); #endif return 1; } }
public static int Run(string[] args) { DebugHelper.HandleDebugSwitch(ref args); var help = false; string helpText = null; var returnCode = 0; RunCommand runCmd = new RunCommand(); try { ArgumentSyntax.Parse(args, syntax => { syntax.HandleHelp = false; syntax.HandleErrors = false; syntax.DefineOption("f|framework", ref runCmd.Framework, "Compile a specific framework"); syntax.DefineOption("c|configuration", ref runCmd.Configuration, "Configuration under which to build"); syntax.DefineOption("p|project", ref runCmd.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"); syntax.DefineOption("h|help", ref help, "Help for compile native."); // TODO: this is not supporting args which can be switches (i.e. --test) // TODO: we need to make a change in System.CommandLine or parse args ourselves. syntax.DefineParameterList("args", ref runCmd.Args, "Arguments to pass to the executable or script"); helpText = syntax.GetHelpText(); }); } catch (ArgumentSyntaxException exception) { Console.Error.WriteLine(exception.Message); help = true; returnCode = 1; } if (help) { Console.WriteLine(helpText); return returnCode; } try { return runCmd.Start(); } catch (Exception ex) { #if DEBUG Console.Error.WriteLine(ex); #else Console.Error.WriteLine(ex.Message); #endif return 1; } }
public static int Run(string[] args) { DebugHelper.HandleDebugSwitch(ref args); CommandLineApplication app = new CommandLineApplication(throwOnUnexpectedArg: false); app.Name = "dotnet run"; app.FullName = ".NET Run Command"; app.Description = "Command used to run .NET apps"; app.HandleResponseFiles = true; app.AllowArgumentSeparator = true; 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); app.OnExecute(() => { RunCommand runCmd = new RunCommand(); runCmd.Framework = framework.Value(); runCmd.Configuration = configuration.Value(); runCmd.Project = project.Value(); runCmd.Args = app.RemainingArguments; return(runCmd.Start()); }); try { return(app.Execute(args)); } catch (Exception ex) { #if DEBUG Reporter.Error.WriteLine(ex.ToString()); #else Reporter.Error.WriteLine(ex.Message); #endif return(1); } }
public static int Run(string[] args) { DebugHelper.HandleDebugSwitch(ref args); CommandLineApplication app = new CommandLineApplication(throwOnUnexpectedArg: false); app.Name = "dotnet run"; app.FullName = ".NET Run Command"; app.Description = "Command used to run .NET apps"; app.HandleResponseFiles = true; app.AllowArgumentSeparator = true; 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); app.OnExecute(() => { RunCommand runCmd = new RunCommand(); runCmd.Framework = framework.Value(); runCmd.Configuration = configuration.Value(); runCmd.Project = project.Value(); runCmd.Args = app.RemainingArguments; return runCmd.Start(); }); try { return app.Execute(args); } catch (Exception ex) { #if DEBUG Reporter.Error.WriteLine(ex.ToString()); #else Reporter.Error.WriteLine(ex.Message); #endif return 1; } }
public static int Run(string[] args) { DebugHelper.HandleDebugSwitch(ref args); CommandLineApplication app = new CommandLineApplication(throwOnUnexpectedArg: false); app.Name = "dotnet run"; app.FullName = LocalizableStrings.AppFullName; app.Description = LocalizableStrings.AppDescription; app.HandleResponseFiles = true; app.AllowArgumentSeparator = true; app.ArgumentSeparatorHelpText = HelpMessageStrings.MSBuildAdditionalArgsHelpText; app.HelpOption("-h|--help"); CommandOption configuration = app.Option( "-c|--configuration", LocalizableStrings.CommandOptionConfigurationDescription, CommandOptionType.SingleValue); CommandOption framework = app.Option( "-f|--framework <{LocalizableStrings.CommandOptionFramework}>", LocalizableStrings.CommandOptionFrameworkDescription, CommandOptionType.SingleValue); CommandOption project = app.Option( "-p|--project", LocalizableStrings.CommandOptionProjectDescription, CommandOptionType.SingleValue); app.OnExecute(() => { RunCommand runCmd = new RunCommand(); runCmd.Configuration = configuration.Value(); runCmd.Framework = framework.Value(); runCmd.Project = project.Value(); runCmd.Args = app.RemainingArguments; return(runCmd.Start()); }); return(app.Execute(args)); }
public static int Run(string[] args) { DebugHelper.HandleDebugSwitch(ref args); CommandLineApplication app = new CommandLineApplication(throwOnUnexpectedArg: false); app.Name = "dotnet run"; app.FullName = ".NET Run Command"; app.Description = "Command used to run .NET apps"; app.HandleResponseFiles = true; app.AllowArgumentSeparator = true; app.ArgumentSeparatorHelpText = HelpMessageStrings.MSBuildAdditionalArgsHelpText; app.HelpOption("-h|--help"); CommandOption configuration = app.Option( "-c|--configuration", "Configuration under which to build", CommandOptionType.SingleValue); CommandOption framework = app.Option( "-f|--framework <FRAMEWORK>", "Compile a specific framework", CommandOptionType.SingleValue); CommandOption project = app.Option( "-p|--project", "The path to the project file to run (defaults to the current directory if there is only one project).", CommandOptionType.SingleValue); app.OnExecute(() => { RunCommand runCmd = new RunCommand(); runCmd.Configuration = configuration.Value(); runCmd.Framework = framework.Value(); runCmd.Project = project.Value(); runCmd.Args = app.RemainingArguments; return(runCmd.Start()); }); return(app.Execute(args)); }
public static RunCommand FromArgs(string[] args) { var parseResult = Parser.Instance.ParseFrom("dotnet run", args); if (parseResult.HasOption("--help")) { parseResult.ShowHelp(); throw new HelpException(string.Empty); } string project = parseResult.ValueForOption <string>(RunCommandParser.ProjectOptionShort); if (!string.IsNullOrEmpty(project)) { Console.WriteLine(LocalizableStrings.RunCommandProjectAbbreviationDeprecated.Yellow()); } else { project = parseResult.ValueForOption <string>(RunCommandParser.ProjectOption); } var command = new RunCommand( configuration: parseResult.ValueForOption <string>(RunCommandParser.ConfigurationOption), framework: parseResult.ValueForOption <string>(RunCommandParser.FrameworkOption), runtime: parseResult.ValueForOption <string>(RunCommandParser.RuntimeOption), noBuild: parseResult.HasOption(RunCommandParser.NoBuildOption), project: project, launchProfile: parseResult.ValueForOption <string>(RunCommandParser.LaunchProfileOption), noLaunchProfile: parseResult.HasOption(RunCommandParser.NoLaunchProfileOption), noRestore: parseResult.HasOption(RunCommandParser.NoRestoreOption) || parseResult.HasOption(RunCommandParser.NoBuildOption), interactive: parseResult.HasOption(RunCommandParser.InteractiveOption), restoreArgs: parseResult.OptionValuesToBeForwarded(RunCommandParser.GetCommand()), args: (parseResult.UnparsedTokens ?? Array.Empty <string>()).Concat(parseResult.UnmatchedTokens ?? Array.Empty <string>()) ); return(command); }