2015-11-16 19:21:57 +00:00
|
|
|
|
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
|
|
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
|
|
|
|
|
|
|
|
using System;
|
2015-11-02 00:21:10 +00:00
|
|
|
|
using System.Collections.Generic;
|
2015-10-06 09:19:27 +00:00
|
|
|
|
using System.Linq;
|
2015-10-06 17:46:43 +00:00
|
|
|
|
using Microsoft.DotNet.Cli.Utils;
|
2015-11-28 08:28:45 +00:00
|
|
|
|
using NuGet.Frameworks;
|
2015-10-03 18:34:08 +00:00
|
|
|
|
|
|
|
|
|
namespace Microsoft.DotNet.Cli
|
|
|
|
|
{
|
|
|
|
|
public class Program
|
|
|
|
|
{
|
2015-11-02 00:21:10 +00:00
|
|
|
|
private const string HelpText = @".NET Command Line Interface
|
|
|
|
|
Usage: dotnet [common-options] [command] [arguments]
|
|
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
|
[command] The command to execute
|
|
|
|
|
[arguments] Arguments to pass to the command
|
|
|
|
|
|
|
|
|
|
Common Options (passed before the command):
|
|
|
|
|
-v|--verbose Enable verbose output
|
|
|
|
|
|
|
|
|
|
Common Commands:
|
|
|
|
|
compile Compiles a .NET project
|
|
|
|
|
publish Publishes a .NET project for deployment
|
|
|
|
|
run Compiles and immediately executes a .NET project";
|
|
|
|
|
|
2015-10-03 18:34:08 +00:00
|
|
|
|
public static int Main(string[] args)
|
|
|
|
|
{
|
2015-11-28 08:28:45 +00:00
|
|
|
|
DebugHelper.HandleDebugSwitch(ref args);
|
|
|
|
|
|
2015-11-02 00:21:10 +00:00
|
|
|
|
// CommandLineApplication is a bit restrictive, so we parse things ourselves here. Individual apps should use CLA.
|
|
|
|
|
var verbose = false;
|
2015-11-17 01:39:03 +00:00
|
|
|
|
var success = true;
|
2015-11-02 00:21:10 +00:00
|
|
|
|
var command = string.Empty;
|
|
|
|
|
var lastArg = 0;
|
|
|
|
|
for (; lastArg < args.Length; lastArg++)
|
2015-10-08 21:49:39 +00:00
|
|
|
|
{
|
2015-11-02 00:21:10 +00:00
|
|
|
|
if (IsArg(args[lastArg], "v", "verbose"))
|
2015-10-08 21:49:39 +00:00
|
|
|
|
{
|
2015-11-02 00:21:10 +00:00
|
|
|
|
verbose = true;
|
|
|
|
|
}
|
2015-11-17 01:39:03 +00:00
|
|
|
|
else if (IsArg(args[lastArg], "h", "help"))
|
|
|
|
|
{
|
|
|
|
|
PrintHelp();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2015-11-02 00:21:10 +00:00
|
|
|
|
else if (args[lastArg].StartsWith("-"))
|
|
|
|
|
{
|
2015-11-17 01:39:03 +00:00
|
|
|
|
Reporter.Error.WriteLine($"Unknown option: {args[lastArg]}");
|
|
|
|
|
success = false;
|
2015-10-08 21:49:39 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-11-02 00:21:10 +00:00
|
|
|
|
// It's the command, and we're done!
|
|
|
|
|
command = args[lastArg];
|
|
|
|
|
break;
|
2015-10-08 21:49:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-11-17 01:39:03 +00:00
|
|
|
|
if (!success) {
|
|
|
|
|
PrintHelp();
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2015-11-02 00:21:10 +00:00
|
|
|
|
|
|
|
|
|
var appArgs = (lastArg + 1) >= args.Length ? Enumerable.Empty<string>() : args.Skip(lastArg + 1).ToArray();
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(command) || command.Equals("help", StringComparison.OrdinalIgnoreCase))
|
2015-10-08 21:49:39 +00:00
|
|
|
|
{
|
2015-11-02 00:21:10 +00:00
|
|
|
|
return RunHelpCommand(appArgs);
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-28 08:28:45 +00:00
|
|
|
|
return Command.Create("dotnet-" + command, appArgs, new NuGetFramework("DNXCore", Version.Parse("5.0")))
|
2015-11-02 00:21:10 +00:00
|
|
|
|
.EnvironmentVariable(CommandContext.Variables.Verbose, verbose.ToString())
|
|
|
|
|
.EnvironmentVariable(CommandContext.Variables.AnsiPassThru, bool.TrueString)
|
|
|
|
|
.ForwardStdErr()
|
|
|
|
|
.ForwardStdOut()
|
|
|
|
|
.Execute()
|
|
|
|
|
.ExitCode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static int RunHelpCommand(IEnumerable<string> appArgs)
|
|
|
|
|
{
|
|
|
|
|
if (appArgs.Any())
|
|
|
|
|
{
|
|
|
|
|
return Command.Create("dotnet-" + appArgs.First(), "--help")
|
2015-10-08 21:49:39 +00:00
|
|
|
|
.ForwardStdErr()
|
|
|
|
|
.ForwardStdOut()
|
2015-10-21 10:11:27 +00:00
|
|
|
|
.Execute()
|
2015-10-08 21:49:39 +00:00
|
|
|
|
.ExitCode;
|
|
|
|
|
}
|
2015-11-02 00:21:10 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
PrintHelp();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-17 04:26:52 +00:00
|
|
|
|
private static void PrintHelp()
|
2015-11-02 00:21:10 +00:00
|
|
|
|
{
|
|
|
|
|
Reporter.Output.WriteLine(HelpText);
|
2015-10-08 21:49:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-11-02 00:21:10 +00:00
|
|
|
|
private static bool IsArg(string candidate, string shortName, string longName)
|
2015-10-08 21:49:39 +00:00
|
|
|
|
{
|
2015-11-02 00:21:10 +00:00
|
|
|
|
return candidate.Equals("-" + shortName) || candidate.Equals("--" + longName);
|
2015-10-06 09:19:27 +00:00
|
|
|
|
}
|
2015-10-03 18:34:08 +00:00
|
|
|
|
}
|
|
|
|
|
}
|