2015-10-03 18:34:08 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2015-10-06 09:19:27 +00:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Linq;
|
2015-10-03 18:34:08 +00:00
|
|
|
|
using Microsoft.Dnx.Runtime.Common.CommandLine;
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.DotNet.Cli
|
|
|
|
|
{
|
|
|
|
|
public class Program
|
|
|
|
|
{
|
|
|
|
|
public static int Main(string[] args)
|
|
|
|
|
{
|
|
|
|
|
var app = new CommandLineApplication();
|
|
|
|
|
app.Name = "dotnet";
|
|
|
|
|
app.Description = "The .NET CLI";
|
|
|
|
|
|
2015-10-06 09:19:27 +00:00
|
|
|
|
// Most commonly used commands
|
2015-10-03 18:34:08 +00:00
|
|
|
|
app.Command("init", c =>
|
|
|
|
|
{
|
|
|
|
|
c.Description = "Scaffold a basic .NET application";
|
|
|
|
|
|
2015-10-06 09:19:27 +00:00
|
|
|
|
c.OnExecute(() => Exec("dotnet-init", c.RemainingArguments));
|
2015-10-03 18:34:08 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.Command("compile", c =>
|
|
|
|
|
{
|
|
|
|
|
c.Description = "Produce assemblies for the project in given directory";
|
|
|
|
|
|
2015-10-06 09:19:27 +00:00
|
|
|
|
c.OnExecute(() =>
|
|
|
|
|
{
|
|
|
|
|
// Temporary!
|
|
|
|
|
return Exec("dnu", new[] { "build" });
|
|
|
|
|
// Exec("dotnet-compile", c.RemainingArguments);
|
|
|
|
|
});
|
2015-10-03 18:34:08 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.Command("restore", c =>
|
|
|
|
|
{
|
|
|
|
|
c.Description = "Restore packages";
|
|
|
|
|
|
2015-10-06 09:19:27 +00:00
|
|
|
|
c.OnExecute(() => Exec("dotnet-restore", c.RemainingArguments));
|
2015-10-03 18:34:08 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.Command("pack", c =>
|
|
|
|
|
{
|
|
|
|
|
c.Description = "Produce a NuGet package";
|
|
|
|
|
|
2015-10-06 09:19:27 +00:00
|
|
|
|
c.OnExecute(() => Exec("dotnet-pack", c.RemainingArguments));
|
2015-10-03 18:34:08 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.Command("publish", c =>
|
|
|
|
|
{
|
|
|
|
|
c.Description = "Produce deployable assets";
|
|
|
|
|
|
2015-10-06 09:19:27 +00:00
|
|
|
|
c.OnExecute(() => Exec("dotnet-publish", c.RemainingArguments));
|
2015-10-03 18:34:08 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.OnExecute(() =>
|
|
|
|
|
{
|
|
|
|
|
app.ShowHelp();
|
|
|
|
|
return 2;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return app.Execute(args);
|
|
|
|
|
}
|
2015-10-06 09:19:27 +00:00
|
|
|
|
|
|
|
|
|
private static int Exec(string executable, IList<string> remainingArguments)
|
|
|
|
|
{
|
|
|
|
|
var comSpec = Environment.GetEnvironmentVariable("ComSpec");
|
|
|
|
|
if (!string.IsNullOrEmpty(comSpec))
|
|
|
|
|
{
|
|
|
|
|
remainingArguments =
|
|
|
|
|
new[] { "/C", "\"", executable }
|
|
|
|
|
.Concat(remainingArguments)
|
|
|
|
|
.Concat(new[] { "\"" })
|
|
|
|
|
.ToArray();
|
|
|
|
|
executable = comSpec;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var psi = new ProcessStartInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = executable,
|
|
|
|
|
Arguments = string.Join(" ", remainingArguments),
|
|
|
|
|
UseShellExecute = false,
|
|
|
|
|
CreateNoWindow = true,
|
|
|
|
|
RedirectStandardError = true,
|
|
|
|
|
RedirectStandardOutput = true
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var process = Process.Start(psi);
|
|
|
|
|
process.ErrorDataReceived += OnProcessErrorDataReceived;
|
|
|
|
|
process.OutputDataReceived += OnProcessOutputDataReceived;
|
|
|
|
|
|
|
|
|
|
process.BeginErrorReadLine();
|
|
|
|
|
process.BeginOutputReadLine();
|
|
|
|
|
|
|
|
|
|
process.WaitForExit();
|
|
|
|
|
|
|
|
|
|
return process.ExitCode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void OnProcessOutputDataReceived(object sender, DataReceivedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(e.Data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void OnProcessErrorDataReceived(object sender, DataReceivedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Console.Error.WriteLine(e.Data);
|
|
|
|
|
}
|
2015-10-03 18:34:08 +00:00
|
|
|
|
}
|
|
|
|
|
}
|