Skip to content

Commit 8925d97

Browse files
authored
Giuliov/issue 142 (#143)
* first attempt * fix test * Check if mapping was deleted (#142) * review exit codes
1 parent 6c5e51e commit 8925d97

23 files changed

+119
-58
lines changed

src/aggregator-cli/CommandBase.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,18 @@ internal int Run(CancellationToken cancellationToken)
4343
t.Wait(cancellationToken);
4444
cancellationToken.ThrowIfCancellationRequested();
4545
int rc = t.Result;
46-
if (rc != 0)
46+
if (rc == ExitCodes.Success)
4747
{
48-
Logger.WriteError("Failed!");
48+
Logger.WriteSuccess("Succeeded");
49+
}
50+
else if (rc == ExitCodes.NotFound)
51+
{
52+
Logger.WriteWarning("Not found");
4953
}
5054
else
5155
{
52-
Logger.WriteSuccess("Succeeded");
56+
Logger.WriteError("Failed!");
5357
}
54-
5558
return rc;
5659
}
5760
catch (Exception ex)
@@ -61,7 +64,7 @@ internal int Run(CancellationToken cancellationToken)
6164
? ex.Message
6265
: ex.InnerException.Message
6366
);
64-
return 99;
67+
return ExitCodes.Unexpected;
6568
}
6669
}
6770

src/aggregator-cli/ExitCodes.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace aggregator.cli
6+
{
7+
internal static class ExitCodes
8+
{
9+
public const int Success = 0;
10+
public const int Failure = 1;
11+
public const int InvalidArguments = 2;
12+
public const int NotFound = 3;
13+
public const int Unexpected = 99;
14+
}
15+
}

src/aggregator-cli/Instances/ConfigureInstanceCommand.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ internal override async Task<int> RunAsync(CancellationToken cancellationToken)
3636
.BuildAsync(cancellationToken);
3737
var instances = new AggregatorInstances(context.Azure, context.Logger, context.Naming);
3838
var instance = context.Naming.Instance(Name, ResourceGroup);
39-
bool ok = false;
4039
if (Authentication)
4140
{
42-
ok = await instances.ChangeAppSettingsAsync(instance, Location, SaveMode, cancellationToken);
43-
} else
41+
bool ok = await instances.ChangeAppSettingsAsync(instance, Location, SaveMode, cancellationToken);
42+
return ok ? ExitCodes.Success : ExitCodes.Failure;
43+
}
44+
else
4445
{
4546
context.Logger.WriteError($"Unsupported command option(s)");
47+
return ExitCodes.InvalidArguments;
4648
}
47-
48-
return ok ? 0 : 1;
4949
}
5050
}
51-
}
51+
}

src/aggregator-cli/Instances/InstallInstanceCommand.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ internal override async Task<int> RunAsync(CancellationToken cancellationToken)
4444
if (!validHostingPlanSkus.Contains(HostingPlanSku))
4545
{
4646
Logger.WriteError($"Invalid value for hostingPlanSku: must be one of {String.Join(",", validHostingPlanSkus)}");
47-
return 2;
47+
return ExitCodes.InvalidArguments;
4848
}
4949
if (!validHostingPlanTiers.Contains(HostingPlanTier))
5050
{
5151
Logger.WriteError($"Invalid value for hostingPlanTier: must be one of {String.Join(",", validHostingPlanTiers)}");
52-
return 2;
52+
return ExitCodes.InvalidArguments;
5353
}
5454
var tuning = new AggregatorInstances.InstanceFineTuning
5555
{
@@ -65,7 +65,7 @@ internal override async Task<int> RunAsync(CancellationToken cancellationToken)
6565
var instances = new AggregatorInstances(context.Azure, context.Logger, context.Naming);
6666
var instance = context.Naming.GetInstanceCreateNames(Name, ResourceGroup);
6767
bool ok = await instances.AddAsync(instance, Location, RequiredVersion, SourceUrl, tuning, cancellationToken);
68-
return ok ? 0 : 1;
68+
return ok ? ExitCodes.Success : ExitCodes.Failure;
6969
}
7070
}
7171
}

src/aggregator-cli/Instances/ListInstancesCommand.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ private async Task<int> ListByLocationAsync(CommandContext context, AggregatorIn
5050
{
5151
context.Logger.WriteInfo($"No aggregator instances found in {Location} Region.");
5252
}
53-
return 0;
53+
return ExitCodes.Success;
5454
}
5555

5656
private async Task<int> ListInResourceGroupAsync(CommandContext context, AggregatorInstances instances, CancellationToken cancellationToken)
@@ -68,7 +68,7 @@ private async Task<int> ListInResourceGroupAsync(CommandContext context, Aggrega
6868
context.Logger.WriteInfo($"No aggregator instances found in {ResourceGroup} Resource Group.");
6969
}
7070

71-
return 0;
71+
return ExitCodes.Success;
7272
}
7373

7474
private static async Task<int> ListAllAsync(CommandContext context, AggregatorInstances instances, CancellationToken cancellationToken)
@@ -80,13 +80,15 @@ private static async Task<int> ListAllAsync(CommandContext context, AggregatorIn
8080
context.Logger.WriteOutput(dataObject);
8181
any = true;
8282
}
83-
8483
if (!any)
8584
{
8685
context.Logger.WriteInfo("No aggregator instances found.");
86+
return ExitCodes.NotFound;
87+
}
88+
else
89+
{
90+
return ExitCodes.Success;
8791
}
88-
89-
return 0;
9092
}
9193
}
9294
}

src/aggregator-cli/Instances/StreamLogsCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ internal override async Task<int> RunAsync(CancellationToken cancellationToken)
2424
var instance = context.Naming.Instance(Instance, ResourceGroup);
2525
var instances = new AggregatorInstances(context.Azure, context.Logger, context.Naming);
2626
bool ok = await instances.StreamLogsAsync(instance, cancellationToken);
27-
return ok ? 0 : 1;
27+
return ok ? ExitCodes.Success : ExitCodes.Failure;
2828
}
2929
}
3030
}

src/aggregator-cli/Instances/UninstallInstanceCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ internal override async Task<int> RunAsync(CancellationToken cancellationToken)
3939

4040
var instances = new AggregatorInstances(context.Azure, context.Logger, context.Naming);
4141
var ok = await instances.RemoveAsync(instance, Location);
42-
return ok ? 0 : 1;
42+
return ok ? ExitCodes.Success : ExitCodes.Failure;
4343
}
4444
}
4545
}

src/aggregator-cli/Instances/UpdateInstance.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ internal override async Task<int> RunAsync(CancellationToken cancellationToken)
3232
var instance = context.Naming.Instance(Instance, ResourceGroup);
3333

3434
bool ok = await instances.UpdateAsync(instance, RequiredVersion, SourceUrl, cancellationToken);
35-
return ok ? 0 : 1;
35+
return ok ? ExitCodes.Success : ExitCodes.Failure;
3636
}
3737
}
3838
}

src/aggregator-cli/Logon/LogonAzureCommand.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ internal override async Task<int> RunAsync(CancellationToken cancellationToken)
3636
if (azure == null)
3737
{
3838
context.Logger.WriteError("Invalid azure credentials");
39-
return 2;
39+
return ExitCodes.InvalidArguments;
4040
}
4141
// FIX #60: call some read API to validate parameters
4242
try
@@ -48,9 +48,9 @@ internal override async Task<int> RunAsync(CancellationToken cancellationToken)
4848
int nl = ex.Message.IndexOf(Environment.NewLine);
4949
string m = nl != -1 ? ex.Message.Remove(nl) : ex.Message;
5050
context.Logger.WriteError("Invalid azure credentials: " + m);
51-
return 2;
51+
return ExitCodes.InvalidArguments;
5252
}
53-
return 0;
53+
return ExitCodes.Success;
5454
}
5555
}
5656
}

src/aggregator-cli/Logon/LogonDevOpsCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ internal override async Task<int> RunAsync(CancellationToken cancellationToken)
3636
if (devops == null)
3737
{
3838
context.Logger.WriteError("Invalid Azure DevOps credentials");
39-
return 2;
39+
return ExitCodes.InvalidArguments;
4040
}
4141

42-
return 0;
42+
return ExitCodes.Success;
4343
}
4444
}
4545
}

0 commit comments

Comments
 (0)