Execute the known commands
- Added dotnet.sh and dotnet.cmd for testing - Still uses dnx and dnu for bootstrapping
This commit is contained in:
parent
abb9aded65
commit
92f20068e7
3 changed files with 80 additions and 25 deletions
8
scripts/dotnet.cmd
Normal file
8
scripts/dotnet.cmd
Normal file
|
@ -0,0 +1,8 @@
|
|||
@Echo OFF
|
||||
SETLOCAL
|
||||
SET ERRORLEVEL=
|
||||
|
||||
dnx %DOTNET_OPTIONS% -p %~dp0..\src\Microsoft.DotNet.Cli run %*
|
||||
|
||||
exit /b %ERRORLEVEL%
|
||||
ENDLOCAL
|
14
scripts/dotnet.sh
Normal file
14
scripts/dotnet.sh
Normal file
|
@ -0,0 +1,14 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
SOURCE="${BASH_SOURCE[0]}"
|
||||
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
|
||||
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
||||
SOURCE="$(readlink "$SOURCE")"
|
||||
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
|
||||
done
|
||||
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
||||
|
||||
# work around restore timeouts on Mono
|
||||
[ -z "$MONO_THREADS_PER_CPU" ] && export MONO_THREADS_PER_CPU=50
|
||||
|
||||
exec "dnx" "$DIR/../src/Microsoft.DotNet.Cli" run "$@"
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using Microsoft.Dnx.Runtime.Common.CommandLine;
|
||||
|
||||
namespace Microsoft.DotNet.Cli
|
||||
|
@ -9,62 +10,49 @@ namespace Microsoft.DotNet.Cli
|
|||
{
|
||||
public static int Main(string[] args)
|
||||
{
|
||||
// TODO: Use System.CommandLine
|
||||
var app = new CommandLineApplication();
|
||||
app.Name = "dotnet";
|
||||
app.Description = "The .NET CLI";
|
||||
|
||||
app.HelpOption("-?|-h|--help");
|
||||
|
||||
// Most commonly used commands
|
||||
app.Command("init", c =>
|
||||
{
|
||||
c.Description = "Scaffold a basic .NET application";
|
||||
|
||||
c.HelpOption("-?|-h|--help");
|
||||
c.OnExecute(() => Exec("dotnet-init", c.RemainingArguments));
|
||||
});
|
||||
|
||||
app.Command("compile", c =>
|
||||
{
|
||||
c.Description = "Produce assemblies for the project in given directory";
|
||||
|
||||
var optionFramework = c.Option("--framework <TARGET_FRAMEWORK>", "A list of target frameworks to build.", CommandOptionType.MultipleValue);
|
||||
var optionOut = c.Option("--out <OUTPUT_DIR>", "Output directory", CommandOptionType.SingleValue);
|
||||
var optionQuiet = c.Option("--quiet", "Do not show output such as dependencies in use",
|
||||
CommandOptionType.NoValue);
|
||||
var argProjectDir = c.Argument(
|
||||
"[projects]",
|
||||
"One or more projects build. If not specified, the project in the current directory will be used.",
|
||||
multipleValues: true);
|
||||
c.HelpOption("-?|-h|--help");
|
||||
c.OnExecute(() =>
|
||||
{
|
||||
// Temporary!
|
||||
return Exec("dnu", new[] { "build" });
|
||||
// Exec("dotnet-compile", c.RemainingArguments);
|
||||
});
|
||||
});
|
||||
|
||||
app.Command("restore", c =>
|
||||
{
|
||||
c.Description = "Restore packages";
|
||||
|
||||
var argRoot = c.Argument("[project]",
|
||||
"List of projects and project folders to restore. Each value can be: a path to a project.json or global.json file, or a folder to recursively search for project.json files.",
|
||||
multipleValues: true);
|
||||
|
||||
var optRuntimes = c.Option("--runtime <RID>",
|
||||
"List of runtime identifiers to restore for",
|
||||
CommandOptionType.MultipleValue);
|
||||
|
||||
c.HelpOption("-?|-h|--help");
|
||||
c.OnExecute(() => Exec("dotnet-restore", c.RemainingArguments));
|
||||
});
|
||||
|
||||
app.Command("pack", c =>
|
||||
{
|
||||
c.Description = "Produce a NuGet package";
|
||||
|
||||
c.HelpOption("-?|-h|--help");
|
||||
c.OnExecute(() => Exec("dotnet-pack", c.RemainingArguments));
|
||||
});
|
||||
|
||||
app.Command("publish", c =>
|
||||
{
|
||||
c.Description = "Produce deployable assets";
|
||||
|
||||
c.HelpOption("-?|-h|--help");
|
||||
c.OnExecute(() => Exec("dotnet-publish", c.RemainingArguments));
|
||||
});
|
||||
|
||||
app.OnExecute(() =>
|
||||
|
@ -76,5 +64,50 @@ namespace Microsoft.DotNet.Cli
|
|||
|
||||
return app.Execute(args);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue