From 550dd7f0629b5a78e108c99dfa73b68ce91d5dba Mon Sep 17 00:00:00 2001 From: David Fowler Date: Tue, 6 Oct 2015 03:10:26 -0700 Subject: [PATCH] Some small tweaks to make development easier - Added scripts directory to path when using dotnet tool - Added dotnet-compile and dotnet-restore --- scripts/dotnet | 3 +++ scripts/dotnet-compile | 1 + scripts/dotnet-compile.cmd | 8 +++++++ scripts/dotnet-restore | 1 + scripts/dotnet-restore.cmd | 8 +++++++ scripts/dotnet.cmd | 3 +++ src/Microsoft.DotNet.Cli/Program.cs | 37 +++++++++++++++++++---------- 7 files changed, 49 insertions(+), 12 deletions(-) create mode 100755 scripts/dotnet-compile create mode 100644 scripts/dotnet-compile.cmd create mode 100755 scripts/dotnet-restore create mode 100644 scripts/dotnet-restore.cmd diff --git a/scripts/dotnet b/scripts/dotnet index ce19c0d16..f9febfed4 100755 --- a/scripts/dotnet +++ b/scripts/dotnet @@ -11,4 +11,7 @@ DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" # work around restore timeouts on Mono [ -z "$MONO_THREADS_PER_CPU" ] && export MONO_THREADS_PER_CPU=50 +# Makes development easier +export PATH=$PATH:$DIR + exec "dnx" -p "$DIR/../src/Microsoft.DotNet.Cli" run "$@" \ No newline at end of file diff --git a/scripts/dotnet-compile b/scripts/dotnet-compile new file mode 100755 index 000000000..b9c15a42d --- /dev/null +++ b/scripts/dotnet-compile @@ -0,0 +1 @@ +exec "dnu" "build" "$@" \ No newline at end of file diff --git a/scripts/dotnet-compile.cmd b/scripts/dotnet-compile.cmd new file mode 100644 index 000000000..28a1aaf3b --- /dev/null +++ b/scripts/dotnet-compile.cmd @@ -0,0 +1,8 @@ +@Echo OFF +SETLOCAL +SET ERRORLEVEL= + +dnu build %* + +exit /b %ERRORLEVEL% +ENDLOCAL \ No newline at end of file diff --git a/scripts/dotnet-restore b/scripts/dotnet-restore new file mode 100755 index 000000000..b642f4122 --- /dev/null +++ b/scripts/dotnet-restore @@ -0,0 +1 @@ +exec "dnu" "restore" "$@" \ No newline at end of file diff --git a/scripts/dotnet-restore.cmd b/scripts/dotnet-restore.cmd new file mode 100644 index 000000000..88cb4c56c --- /dev/null +++ b/scripts/dotnet-restore.cmd @@ -0,0 +1,8 @@ +@Echo OFF +SETLOCAL +SET ERRORLEVEL= + +dnu restore %* + +exit /b %ERRORLEVEL% +ENDLOCAL \ No newline at end of file diff --git a/scripts/dotnet.cmd b/scripts/dotnet.cmd index ce90beb34..dc014d3f4 100644 --- a/scripts/dotnet.cmd +++ b/scripts/dotnet.cmd @@ -2,6 +2,9 @@ SETLOCAL SET ERRORLEVEL= +REM makes testing easier for now +set PATH=%PATH%;%~dp0 + dnx %DOTNET_OPTIONS% -p %~dp0..\src\Microsoft.DotNet.Cli run %* exit /b %ERRORLEVEL% diff --git a/src/Microsoft.DotNet.Cli/Program.cs b/src/Microsoft.DotNet.Cli/Program.cs index 637edd266..3065b85bd 100644 --- a/src/Microsoft.DotNet.Cli/Program.cs +++ b/src/Microsoft.DotNet.Cli/Program.cs @@ -26,12 +26,7 @@ namespace Microsoft.DotNet.Cli { c.Description = "Produce assemblies for the project in given directory"; - c.OnExecute(() => - { - // Temporary! - return Exec("dnu", new[] { "build" }); - // Exec("dotnet-compile", c.RemainingArguments); - }); + c.OnExecute(() => Exec("dotnet-compile", c.RemainingArguments)); }); app.Command("restore", c => @@ -54,6 +49,8 @@ namespace Microsoft.DotNet.Cli c.OnExecute(() => Exec("dotnet-publish", c.RemainingArguments)); }); + + // TODO: Handle unknown commands app.OnExecute(() => { @@ -61,27 +58,43 @@ namespace Microsoft.DotNet.Cli return 2; }); - - return app.Execute(args); + try + { + return app.Execute(args); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + return 1; } - private static int Exec(string executable, IList remainingArguments) + private static int Exec(string executable, IList args) { var comSpec = Environment.GetEnvironmentVariable("ComSpec"); if (!string.IsNullOrEmpty(comSpec)) { - remainingArguments = + args = new[] { "/C", "\"", executable } - .Concat(remainingArguments) + .Concat(args) .Concat(new[] { "\"" }) .ToArray(); executable = comSpec; } + else + { + // Temporary, we're doing this so that redirecting the output works + args = new[] { "bash", "-c", "\"", executable } + .Concat(args.Select(argument => argument.Replace("\"", "\\\""))) + .Concat(new[] { "\"" }) + .ToArray(); + executable = "/usr/bin/env"; + } var psi = new ProcessStartInfo { FileName = executable, - Arguments = string.Join(" ", remainingArguments), + Arguments = string.Join(" ", args), UseShellExecute = false, CreateNoWindow = true, RedirectStandardError = true,