Skip to content

Commit 2db5c9e

Browse files
committed
Merge pull request #1499 from stankovski/johanc
Plumb error reporting through (0 on success, non 0 on errors reported)
2 parents e7ac156 + f851c3e commit 2db5c9e

22 files changed

+415
-97
lines changed

build.proj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@
317317
<Message Importance="high" Text="Running check in tests..." />
318318
<ItemGroup>
319319
<!--Exclude 1 test projects still in progress with build failures-->
320-
<_CLUTestProjects Include="$(CLURootDir)\*.Test\project.json">
320+
<_CLUTestProjects Include="$(CLURootDir)\*.Test\project.json" Exclude="$(CLURootDir)\Microsoft.CLU.Test\project.json">
321321
</_CLUTestProjects>
322322
</ItemGroup>
323323
<Exec Command="dnu build" WorkingDirectory="%(_CLUTestProjects.RootDir)%(_CLUTestProjects.Directory)" />

src/CLU/CLUCoreCLR.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.CLU.Run", "Micros
3737
EndProject
3838
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.CLU", "Microsoft.CLU\Microsoft.CLU.xproj", "{D0A59671-088D-463B-B060-2ADAFFB9C3F6}"
3939
EndProject
40+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.CLU.Test", "Microsoft.CLU.Test\Microsoft.CLU.Test.xproj", "{91422B55-28A5-48DE-BCA0-30C3E30FFB1C}"
41+
EndProject
4042
Global
4143
GlobalSection(SolutionConfigurationPlatforms) = preSolution
4244
Debug|Any CPU = Debug|Any CPU
@@ -111,6 +113,10 @@ Global
111113
{D0A59671-088D-463B-B060-2ADAFFB9C3F6}.Debug|Any CPU.Build.0 = Debug|Any CPU
112114
{D0A59671-088D-463B-B060-2ADAFFB9C3F6}.Release|Any CPU.ActiveCfg = Release|Any CPU
113115
{D0A59671-088D-463B-B060-2ADAFFB9C3F6}.Release|Any CPU.Build.0 = Release|Any CPU
116+
{91422B55-28A5-48DE-BCA0-30C3E30FFB1C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
117+
{91422B55-28A5-48DE-BCA0-30C3E30FFB1C}.Debug|Any CPU.Build.0 = Debug|Any CPU
118+
{91422B55-28A5-48DE-BCA0-30C3E30FFB1C}.Release|Any CPU.ActiveCfg = Release|Any CPU
119+
{91422B55-28A5-48DE-BCA0-30C3E30FFB1C}.Release|Any CPU.Build.0 = Release|Any CPU
114120
EndGlobalSection
115121
GlobalSection(SolutionProperties) = preSolution
116122
HideSolutionNode = FALSE

src/CLU/Microsoft.CLU/CommandModel/ICommandModel.cs renamed to src/CLU/Microsoft.CLU.Common/ICommandModel.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
namespace Microsoft.CLU
22
{
3+
public enum CommandModelErrorCode
4+
{
5+
Success = 0,
6+
InternalFailure = -1,
7+
NonTerminatingError = 1,
8+
TerminatingError = 2,
9+
CommandNotFound = 3,
10+
11+
MissingParameters = 10,
12+
13+
PackageNotFound = 20
14+
}
15+
316
/// <summary>
417
/// The contract that different "Programming Model" model classes needs to implement.
518
/// </summary>
@@ -10,6 +23,6 @@ public interface ICommandModel
1023
/// </summary>
1124
/// <param name="commandConfiguration">Date from the command configuration file.</param>
1225
/// <param name="arguments">The command-line arguments array</param>
13-
void Run(ConfigurationDictionary commandConfiguration, string[] arguments);
26+
CommandModelErrorCode Run(ConfigurationDictionary commandConfiguration, string[] arguments);
1427
}
1528
}

src/CLU/Microsoft.CLU.Run/CommandExecMode.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ public bool CanHandle(string[] arguments)
2727
/// IRunMode implementation for executing command.
2828
/// </summary>
2929
/// <param name="arguments">The arguments</param>
30-
public void Run(string[] arguments)
30+
public Microsoft.CLU.CommandModelErrorCode Run(string[] arguments)
3131
{
3232
if (arguments.Length < 2)
3333
{
3434
CLUEnvironment.Console.WriteErrorLine(Strings.CommandExecMode_Run_MissingCommandConfigFileArgument);
35-
return;
35+
return Microsoft.CLU.CommandModelErrorCode.MissingParameters;
3636
}
3737

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

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

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

80-
CommandModel.Run(commandConfiguration, GetModelArguments(arguments, argsBase));
80+
return CommandModel.Run(commandConfiguration, GetModelArguments(arguments, argsBase));
8181
}
8282
catch (TargetInvocationException tie)
8383
{
@@ -89,6 +89,8 @@ public void Run(string[] arguments)
8989
CLUEnvironment.Console.WriteErrorLine(exc.Message);
9090
CLUEnvironment.Console.WriteDebugLine($"{exc.GetType().FullName}\n{exc.StackTrace}");
9191
}
92+
93+
return CommandModelErrorCode.InternalFailure;
9294
}
9395

9496
#endregion

src/CLU/Microsoft.CLU.Run/CommandModel.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ internal class CommandModel
1919
/// </summary>
2020
/// <param name="commandConfiguration"></param>
2121
/// <param name="modelArguments"></param>
22-
public static void Run(CommandConfig commandConfiguration, string[] modelArguments)
22+
public static Microsoft.CLU.CommandModelErrorCode Run(CommandConfig commandConfiguration, string[] modelArguments)
2323
{
2424
CommandModel commandModel = new CommandModel()
2525
{
2626
_commandConfiguration = commandConfiguration,
2727
_modelArguments = modelArguments
2828
};
2929
commandModel.ResolveModel();
30-
commandModel.Run();
30+
return commandModel.Run();
3131
}
3232

3333
/// <summary>
@@ -62,19 +62,21 @@ private void ResolveModel()
6262
/// <summary>
6363
/// Runs the model
6464
/// </summary>
65-
private void Run()
65+
private CommandModelErrorCode Run()
6666
{
67+
object returnValue = null;
6768
if (_entryPoint.ClassType.GetInterfaces().Where(t => String.Equals(t.FullName, Common.Constants.CommandModelInterface, StringComparison.Ordinal)).FirstOrDefault() != null)
6869
{
6970
var model = Activator.CreateInstance(_entryPoint.ClassType);
7071
var configDict = ConfigurationDictionary.Create(_commandConfiguration.Items);
71-
_entryPoint.Method.Invoke(model, new object[] { configDict, _modelArguments });
72+
returnValue = _entryPoint.Method.Invoke(model, new object[] { configDict, _modelArguments });
7273
}
7374
else
7475
{
7576
ValidateCustomEntryPoint();
76-
_entryPoint.Method.Invoke(null, new object[] { _modelArguments });
77+
returnValue = _entryPoint.Method.Invoke(null, new object[] { _modelArguments });
7778
}
79+
return (CommandModelErrorCode) returnValue;
7880
}
7981

8082
/// <summary>

src/CLU/Microsoft.CLU.Run/IRunMode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ internal interface IRunMode
1717
/// IRunMode implementation.
1818
/// </summary>
1919
/// <param name="arguments">The arguments</param>
20-
void Run(string[] arguments);
20+
Microsoft.CLU.CommandModelErrorCode Run(string[] arguments);
2121
}
2222
}

src/CLU/Microsoft.CLU.Run/PackageManagementMode.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public bool CanHandle(string[] arguments)
3333
/// IRunMode implementation for package managment.
3434
/// </summary>
3535
/// <param name="arguments">The arguments</param>
36-
public void Run(string[] arguments)
36+
public Microsoft.CLU.CommandModelErrorCode Run(string[] arguments)
3737
{
3838
_packagesRootPath = CLUEnvironment.GetPackagesRootPath();
3939
try
@@ -44,13 +44,13 @@ public void Run(string[] arguments)
4444
{
4545
CLUEnvironment.Console.WriteErrorLine(tie.InnerException.Message);
4646
CLUEnvironment.Console.WriteDebugLine($"{tie.InnerException.GetType().FullName}\n{tie.InnerException.StackTrace}");
47-
return;
47+
return Microsoft.CLU.CommandModelErrorCode.InternalFailure;
4848
}
4949
catch (Exception exc)
5050
{
5151
CLUEnvironment.Console.WriteErrorLine(exc.Message);
5252
CLUEnvironment.Console.WriteDebugLine($"{exc.GetType().FullName}\n{exc.StackTrace}");
53-
return;
53+
return Microsoft.CLU.CommandModelErrorCode.InternalFailure;
5454
}
5555

5656
try
@@ -77,7 +77,7 @@ public void Run(string[] arguments)
7777
arguments[argsBase + 1].StartsWith("-", StringComparison.Ordinal))
7878
{
7979
CLUEnvironment.Console.WriteLine(Strings.PackageManagementMode_Run_VersionIdMissing);
80-
return;
80+
return Microsoft.CLU.CommandModelErrorCode.MissingParameters;
8181
}
8282
version = arguments[argsBase + 1];
8383
argsBase += 2;
@@ -145,12 +145,16 @@ public void Run(string[] arguments)
145145
{
146146
CLUEnvironment.Console.WriteErrorLine(tie.InnerException.Message);
147147
CLUEnvironment.Console.WriteDebugLine($"{tie.InnerException.GetType().FullName}\n{tie.InnerException.StackTrace}");
148+
return Microsoft.CLU.CommandModelErrorCode.InternalFailure;
148149
}
149150
catch (Exception exc)
150151
{
151152
CLUEnvironment.Console.WriteErrorLine(exc.Message);
152153
CLUEnvironment.Console.WriteDebugLine($"{exc.GetType().FullName}\n{exc.StackTrace}");
154+
return Microsoft.CLU.CommandModelErrorCode.InternalFailure;
153155
}
156+
157+
return CommandModelErrorCode.Success;
154158
}
155159

156160
/// <summary>

src/CLU/Microsoft.CLU.Run/Program.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ namespace Microsoft.CLU.Run
1111
/// </summary>
1212
public class CLURun
1313
{
14+
public static void Main(string[] args) { }
15+
1416
/// <summary>
1517
/// Microsoft.CLU.Run (clurun.exe) main entry point.
1618
/// </summary>
1719
/// <param name="args">The commandline arguments</param>
18-
public static void Main(string[] args)
20+
public static Microsoft.CLU.CommandModelErrorCode Execute(string[] args)
1921
{
2022
CLUEnvironment.Console = new ConsoleInputOutput(args);
2123

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

2628
CLURun cluRun = new CLURun();
27-
cluRun.Parse(args);
29+
var result = cluRun.Parse(args);
2830

2931
sw.Stop();
3032
CLUEnvironment.Console.WriteDebugLine($"The command executed in {sw.ElapsedMilliseconds} ms");
33+
return result;
3134
}
3235
catch (Exception exc)
3336
{
3437
CLUEnvironment.Console.WriteErrorLine(exc.Message);
3538
CLUEnvironment.Console.WriteDebugLine(exc.StackTrace);
39+
return Microsoft.CLU.CommandModelErrorCode.InternalFailure;
3640
}
3741
}
3842

3943
/// <summary>
4044
/// Parse the commandline argument and bootstrap the command execution.
4145
/// </summary>
4246
/// <param name="arguments">The commandline arguments</param>
43-
private void Parse(string [] arguments)
47+
private Microsoft.CLU.CommandModelErrorCode Parse(string [] arguments)
4448
{
4549
if (arguments.Count() == 0)
4650
{
4751
DisplayHelp();
48-
return;
52+
return CommandModelErrorCode.MissingParameters;
4953
}
5054

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

5761
// Run the command.
58-
mode.Run(arguments);
62+
return mode.Run(arguments);
5963
}
6064

6165

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
RtPackage: Microsoft.CLU.Commands
2+
RtEntry: Microsoft.CLU.CommandModel.CmdletCommandModel.Run
3+
RtAssembly: Microsoft.CLU.dll
4+
Modules: Microsoft.CLU.Test
5+
NounPrefix: AzureRm
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Name: Microsoft.CLU.Test
2+
CommandAssemblies: Microsoft.CLU.Test.dll
3+
NounPrefix: Test
4+
NounFirst: true
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0"?>
2+
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
3+
<metadata minClientVersion="2.5">
4+
<id>Microsoft.CLU.Test</id>
5+
<title>Microsoft CLU CommandLine test command packge</title>
6+
<version>%PackageVersion%</version>
7+
<authors>Microsoft</authors>
8+
<owners>azure-sdk, PowerShell, Microsoft</owners>
9+
<licenseUrl>http://aka.ms/windowsazureapache2</licenseUrl>
10+
<projectUrl>https://github.com/Azure/azure-powershell</projectUrl>
11+
<iconUrl>http://go.microsoft.com/fwlink/?LinkID=288890</iconUrl>
12+
<requireLicenseAcceptance>true</requireLicenseAcceptance>
13+
<summary>Execution package for Microsoft CLU packages</summary>
14+
<description>
15+
Cross-Platform command package for clurun
16+
17+
Supported Library Platforms:
18+
- .NET Framework 5.0
19+
</description>
20+
<copyright>Copyright © Microsoft Corporation</copyright>
21+
<tags>Private test</tags>
22+
<references>
23+
<group targetFramework="dnxcore50">
24+
%ReferenceFiles% </group>
25+
</references>
26+
<dependencies/>
27+
</metadata>
28+
<files>
29+
%SourceFiles%%ContentFiles% </files>
30+
</package>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0.24711" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0.24711</VisualStudioVersion>
5+
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
6+
</PropertyGroup>
7+
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
8+
<PropertyGroup Label="Globals">
9+
<ProjectGuid>91422b55-28a5-48de-bca0-30c3e30ffb1c</ProjectGuid>
10+
<RootNamespace>Microsoft.Azure.Commands.Resources.Test</RootNamespace>
11+
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
12+
<OutputPath Condition="'$(OutputPath)'=='' ">..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
13+
</PropertyGroup>
14+
<PropertyGroup>
15+
<SchemaVersion>2.0</SchemaVersion>
16+
</PropertyGroup>
17+
<ItemGroup>
18+
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
19+
</ItemGroup>
20+
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
21+
</Project>

0 commit comments

Comments
 (0)