2015-10-30 10:34:02 -07:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using Microsoft.Dnx.Runtime.Common.CommandLine;
|
|
|
|
|
using Microsoft.DotNet.Cli.Utils;
|
|
|
|
|
|
2015-11-06 16:11:09 -08:00
|
|
|
|
namespace Microsoft.DotNet.Tools.Repl.Csi
|
2015-10-30 10:34:02 -07:00
|
|
|
|
{
|
|
|
|
|
public sealed class Program
|
|
|
|
|
{
|
|
|
|
|
public static int Main(string[] args)
|
|
|
|
|
{
|
|
|
|
|
DebugHelper.HandleDebugSwitch(ref args);
|
|
|
|
|
|
|
|
|
|
var app = new CommandLineApplication();
|
2015-11-06 16:11:09 -08:00
|
|
|
|
app.Name = "dotnet repl csi";
|
|
|
|
|
app.FullName = "C# REPL";
|
|
|
|
|
app.Description = "C# REPL for the .NET platform";
|
2015-10-30 10:34:02 -07:00
|
|
|
|
app.HelpOption("-h|--help");
|
|
|
|
|
var script = app.Argument("<SCRIPT>", "The .csx file to run. Defaults to interactive mode.");
|
|
|
|
|
|
|
|
|
|
app.OnExecute(() => Run(script.Value));
|
|
|
|
|
return app.Execute(args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static int Run(string scriptOpt)
|
|
|
|
|
{
|
|
|
|
|
var corerun = Path.Combine(AppContext.BaseDirectory, Constants.HostExecutableName);
|
|
|
|
|
var csiExe = Path.Combine(AppContext.BaseDirectory, "csi.exe");
|
|
|
|
|
var csiArgs = string.IsNullOrEmpty(scriptOpt) ? "-i" : scriptOpt;
|
|
|
|
|
var command = File.Exists(corerun) && File.Exists(csiExe) ?
|
|
|
|
|
Command.Create(corerun, $@"""{csiExe}"" {csiArgs}") :
|
|
|
|
|
Command.Create(csiExe, csiArgs);
|
|
|
|
|
command = command.ForwardStdOut().ForwardStdErr();
|
|
|
|
|
var result = command.Execute();
|
|
|
|
|
return result.ExitCode;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|