Skip to content

Plumb error reporting through (0 on success, non 0 on errors reported) #1474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Dec 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/CLU/CLUCoreCLR.sln
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.CLU.Run", "Micros
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.CLU", "Microsoft.CLU\Microsoft.CLU.xproj", "{D0A59671-088D-463B-B060-2ADAFFB9C3F6}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.CLU.Test", "Microsoft.CLU.Test\Microsoft.CLU.Test.xproj", "{91422B55-28A5-48DE-BCA0-30C3E30FFB1C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -111,6 +113,10 @@ Global
{D0A59671-088D-463B-B060-2ADAFFB9C3F6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D0A59671-088D-463B-B060-2ADAFFB9C3F6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D0A59671-088D-463B-B060-2ADAFFB9C3F6}.Release|Any CPU.Build.0 = Release|Any CPU
{91422B55-28A5-48DE-BCA0-30C3E30FFB1C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{91422B55-28A5-48DE-BCA0-30C3E30FFB1C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{91422B55-28A5-48DE-BCA0-30C3E30FFB1C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{91422B55-28A5-48DE-BCA0-30C3E30FFB1C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
namespace Microsoft.CLU
{
public enum CommandModelErrorCode
{
Success = 0,
InternalFailure = -1,
NonTerminatingError = 1,
TerminatingError = 2,
CommandNotFound = 3,

MissingParameters = 10,

PackageNotFound = 20
}

/// <summary>
/// The contract that different "Programming Model" model classes needs to implement.
/// </summary>
Expand All @@ -10,6 +23,6 @@ public interface ICommandModel
/// </summary>
/// <param name="commandConfiguration">Date from the command configuration file.</param>
/// <param name="arguments">The command-line arguments array</param>
void Run(ConfigurationDictionary commandConfiguration, string[] arguments);
CommandModelErrorCode Run(ConfigurationDictionary commandConfiguration, string[] arguments);
}
}
12 changes: 7 additions & 5 deletions src/CLU/Microsoft.CLU.Run/CommandExecMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ public bool CanHandle(string[] arguments)
/// IRunMode implementation for executing command.
/// </summary>
/// <param name="arguments">The arguments</param>
public void Run(string[] arguments)
public Microsoft.CLU.CommandModelErrorCode Run(string[] arguments)
{
if (arguments.Length < 2)
{
CLUEnvironment.Console.WriteErrorLine(Strings.CommandExecMode_Run_MissingCommandConfigFileArgument);
return;
return Microsoft.CLU.CommandModelErrorCode.MissingParameters;
}

try
Expand All @@ -52,7 +52,7 @@ public void Run(string[] arguments)
arguments[argsBase + 1].StartsWith("-", StringComparison.Ordinal))
{
CLUEnvironment.Console.WriteErrorLine(Strings.CommandExecMode_Run_MissingScriptName);
return;
return Microsoft.CLU.CommandModelErrorCode.MissingParameters;
}

CLUEnvironment.ScriptName = arguments[argsBase + 1];
Expand All @@ -65,7 +65,7 @@ public void Run(string[] arguments)
arguments[argsBase + 1].StartsWith("-", StringComparison.Ordinal))
{
CLUEnvironment.Console.WriteErrorLine(Strings.CommandExecMode_Run_MissingScriptConfigFileName);
return;
return Microsoft.CLU.CommandModelErrorCode.MissingParameters;
}

commandConfiguration = CommandConfig.Load(arguments[argsBase + 1]);
Expand All @@ -77,7 +77,7 @@ public void Run(string[] arguments)
}
}

CommandModel.Run(commandConfiguration, GetModelArguments(arguments, argsBase));
return CommandModel.Run(commandConfiguration, GetModelArguments(arguments, argsBase));
}
catch (TargetInvocationException tie)
{
Expand All @@ -89,6 +89,8 @@ public void Run(string[] arguments)
CLUEnvironment.Console.WriteErrorLine(exc.Message);
CLUEnvironment.Console.WriteDebugLine($"{exc.GetType().FullName}\n{exc.StackTrace}");
}

return CommandModelErrorCode.InternalFailure;
}

#endregion
Expand Down
12 changes: 7 additions & 5 deletions src/CLU/Microsoft.CLU.Run/CommandModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ internal class CommandModel
/// </summary>
/// <param name="commandConfiguration"></param>
/// <param name="modelArguments"></param>
public static void Run(CommandConfig commandConfiguration, string[] modelArguments)
public static Microsoft.CLU.CommandModelErrorCode Run(CommandConfig commandConfiguration, string[] modelArguments)
{
CommandModel commandModel = new CommandModel()
{
_commandConfiguration = commandConfiguration,
_modelArguments = modelArguments
};
commandModel.ResolveModel();
commandModel.Run();
return commandModel.Run();
}

/// <summary>
Expand Down Expand Up @@ -62,19 +62,21 @@ private void ResolveModel()
/// <summary>
/// Runs the model
/// </summary>
private void Run()
private CommandModelErrorCode Run()
{
object returnValue = null;
if (_entryPoint.ClassType.GetInterfaces().Where(t => String.Equals(t.FullName, Common.Constants.CommandModelInterface, StringComparison.Ordinal)).FirstOrDefault() != null)
{
var model = Activator.CreateInstance(_entryPoint.ClassType);
var configDict = ConfigurationDictionary.Create(_commandConfiguration.Items);
_entryPoint.Method.Invoke(model, new object[] { configDict, _modelArguments });
returnValue = _entryPoint.Method.Invoke(model, new object[] { configDict, _modelArguments });
}
else
{
ValidateCustomEntryPoint();
_entryPoint.Method.Invoke(null, new object[] { _modelArguments });
returnValue = _entryPoint.Method.Invoke(null, new object[] { _modelArguments });
}
return (CommandModelErrorCode) returnValue;
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/CLU/Microsoft.CLU.Run/IRunMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ internal interface IRunMode
/// IRunMode implementation.
/// </summary>
/// <param name="arguments">The arguments</param>
void Run(string[] arguments);
Microsoft.CLU.CommandModelErrorCode Run(string[] arguments);
}
}
12 changes: 8 additions & 4 deletions src/CLU/Microsoft.CLU.Run/PackageManagementMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public bool CanHandle(string[] arguments)
/// IRunMode implementation for package managment.
/// </summary>
/// <param name="arguments">The arguments</param>
public void Run(string[] arguments)
public Microsoft.CLU.CommandModelErrorCode Run(string[] arguments)
{
_packagesRootPath = CLUEnvironment.GetPackagesRootPath();
try
Expand All @@ -44,13 +44,13 @@ public void Run(string[] arguments)
{
CLUEnvironment.Console.WriteErrorLine(tie.InnerException.Message);
CLUEnvironment.Console.WriteDebugLine($"{tie.InnerException.GetType().FullName}\n{tie.InnerException.StackTrace}");
return;
return Microsoft.CLU.CommandModelErrorCode.InternalFailure;
}
catch (Exception exc)
{
CLUEnvironment.Console.WriteErrorLine(exc.Message);
CLUEnvironment.Console.WriteDebugLine($"{exc.GetType().FullName}\n{exc.StackTrace}");
return;
return Microsoft.CLU.CommandModelErrorCode.InternalFailure;
}

try
Expand All @@ -77,7 +77,7 @@ public void Run(string[] arguments)
arguments[argsBase + 1].StartsWith("-", StringComparison.Ordinal))
{
CLUEnvironment.Console.WriteLine(Strings.PackageManagementMode_Run_VersionIdMissing);
return;
return Microsoft.CLU.CommandModelErrorCode.MissingParameters;
}
version = arguments[argsBase + 1];
argsBase += 2;
Expand Down Expand Up @@ -145,12 +145,16 @@ public void Run(string[] arguments)
{
CLUEnvironment.Console.WriteErrorLine(tie.InnerException.Message);
CLUEnvironment.Console.WriteDebugLine($"{tie.InnerException.GetType().FullName}\n{tie.InnerException.StackTrace}");
return Microsoft.CLU.CommandModelErrorCode.InternalFailure;
}
catch (Exception exc)
{
CLUEnvironment.Console.WriteErrorLine(exc.Message);
CLUEnvironment.Console.WriteDebugLine($"{exc.GetType().FullName}\n{exc.StackTrace}");
return Microsoft.CLU.CommandModelErrorCode.InternalFailure;
}

return CommandModelErrorCode.Success;
}

/// <summary>
Expand Down
14 changes: 9 additions & 5 deletions src/CLU/Microsoft.CLU.Run/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ namespace Microsoft.CLU.Run
/// </summary>
public class CLURun
{
public static void Main(string[] args) { }

/// <summary>
/// Microsoft.CLU.Run (clurun.exe) main entry point.
/// </summary>
/// <param name="args">The commandline arguments</param>
public static void Main(string[] args)
public static Microsoft.CLU.CommandModelErrorCode Execute(string[] args)
{
CLUEnvironment.Console = new ConsoleInputOutput(args);

Expand All @@ -24,28 +26,30 @@ public static void Main(string[] args)
Stopwatch sw = Stopwatch.StartNew();

CLURun cluRun = new CLURun();
cluRun.Parse(args);
var result = cluRun.Parse(args);

sw.Stop();
CLUEnvironment.Console.WriteDebugLine($"The command executed in {sw.ElapsedMilliseconds} ms");
return result;
}
catch (Exception exc)
{
CLUEnvironment.Console.WriteErrorLine(exc.Message);
CLUEnvironment.Console.WriteDebugLine(exc.StackTrace);
return Microsoft.CLU.CommandModelErrorCode.InternalFailure;
}
}

/// <summary>
/// Parse the commandline argument and bootstrap the command execution.
/// </summary>
/// <param name="arguments">The commandline arguments</param>
private void Parse(string [] arguments)
private Microsoft.CLU.CommandModelErrorCode Parse(string [] arguments)
{
if (arguments.Count() == 0)
{
DisplayHelp();
return;
return CommandModelErrorCode.MissingParameters;
}

var mode = GetMode(arguments);
Expand All @@ -55,7 +59,7 @@ private void Parse(string [] arguments)
CLUEnvironment.SetRootPaths(rootPath);

// Run the command.
mode.Run(arguments);
return mode.Run(arguments);
}


Expand Down
5 changes: 5 additions & 0 deletions src/CLU/Microsoft.CLU.Test/Content/azure.lx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
RtPackage: Microsoft.CLU.Commands
RtEntry: Microsoft.CLU.CommandModel.CmdletCommandModel.Run
RtAssembly: Microsoft.CLU.dll
Modules: Microsoft.CLU.Test
NounPrefix: AzureRm
4 changes: 4 additions & 0 deletions src/CLU/Microsoft.CLU.Test/Content/package.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Name: Microsoft.CLU.Test
CommandAssemblies: Microsoft.CLU.Test.dll
NounPrefix: Test
NounFirst: true
30 changes: 30 additions & 0 deletions src/CLU/Microsoft.CLU.Test/Microsoft.CLU.Test.nuspec.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata minClientVersion="2.5">
<id>Microsoft.CLU.Test</id>
<title>Microsoft CLU CommandLine test command packge</title>
<version>%PackageVersion%</version>
<authors>Microsoft</authors>
<owners>azure-sdk, PowerShell, Microsoft</owners>
<licenseUrl>http://aka.ms/windowsazureapache2</licenseUrl>
<projectUrl>https://github.com/Azure/azure-powershell</projectUrl>
<iconUrl>http://go.microsoft.com/fwlink/?LinkID=288890</iconUrl>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<summary>Execution package for Microsoft CLU packages</summary>
<description>
Cross-Platform command package for clurun

Supported Library Platforms:
- .NET Framework 5.0
</description>
<copyright>Copyright © Microsoft Corporation</copyright>
<tags>Private test</tags>
<references>
<group targetFramework="dnxcore50">
%ReferenceFiles% </group>
</references>
<dependencies/>
</metadata>
<files>
%SourceFiles%%ContentFiles% </files>
</package>
21 changes: 21 additions & 0 deletions src/CLU/Microsoft.CLU.Test/Microsoft.CLU.Test.xproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0.24711" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0.24711</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>91422b55-28a5-48de-bca0-30c3e30ffb1c</ProjectGuid>
<RootNamespace>Microsoft.Azure.Commands.Resources.Test</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
Loading