Skip to content

Commit

Permalink
Fix #31
Browse files Browse the repository at this point in the history
  • Loading branch information
z4kn4fein committed Aug 22, 2024
1 parent b6caae5 commit 1e26d0c
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 53 deletions.
11 changes: 8 additions & 3 deletions src/ConfigCat.Cli.Models/Api/FlagModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json.Serialization;

namespace ConfigCat.Cli.Models.Api;

Expand All @@ -18,13 +20,16 @@ public class FlagModel
public string Hint { get; set; }

public string SettingType { get; set; }

public DateTime? CreatedAt { get; set; }

public string OwnerUserFullName { get; set; }
public string CreatorEmail { get; set; }

public string OwnerUserEmail { get; set; }
public string CreatorFullName { get; set; }

public List<TagModel> Tags { get; set; }

[JsonIgnore]
public List<string> Aliases { get; set; } = [];

public UpdateFlagModel ToUpdateModel() =>
Expand Down
46 changes: 46 additions & 0 deletions src/ConfigCat.Cli.Models/JsonOutputs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System.Collections.Generic;
using ConfigCat.Cli.Models.Api;

namespace ConfigCat.Cli.Models;

public class FlagValueJsonOutput
{
public FlagModel Setting { get; set; }

public IEnumerable<ValueInEnvironmentJsonOutput> Values { get; set; }
}

public class ValueInEnvironmentJsonOutput
{
public string EnvironmentId { get; set; }

public string EnvironmentName { get; set; }

public List<PercentageModel> PercentageRules { get; set; }

public List<TargetingModel> TargetingRules { get; set; }

public object Value { get; set; }
}

public class FlagValueV2JsonOutput
{
public FlagModel Setting { get; set; }
public IEnumerable<ValueV2InEnvironmentJsonOutput> Values { get; set; }
}

public class ValueV2InEnvironmentJsonOutput
{
public string EnvironmentId { get; set; }
public string EnvironmentName { get; set; }
public ValueModel DefaultValue { get; set; }
public List<TargetingRuleModel> TargetingRules { get; set; }
public string PercentageEvaluationAttribute { get; set; }
}

public class ProductJsonOutput : ProductModel
{
public IEnumerable<EnvironmentModel> Environments { get; set; }

public IEnumerable<ConfigModel> Configs { get; set; }
}
2 changes: 1 addition & 1 deletion src/ConfigCat.Cli.Services/Extensions/SystemExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,5 @@ public static string TrimToFitColumn(this string text)
=> text == null ? "\"\"" : $"\"{text.TrimToLength(30)}\"";

public static string TrimToLength(this string text, int length)
=> text.Length > length ? $"{text[0..(length - 2)]}..." : text;
=> text.Length > length ? $"{text[..(length - 2)]}..." : text;
}
6 changes: 3 additions & 3 deletions src/ConfigCat.Cli/Commands/Flags/Flag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ public async Task<int> ListAllFlagsAsync(string configId, string tagName, int? t
var itemsToRender = flags.Select(f => new
{
Id = f.SettingId,
f.Name,
f.Key,
Name = f.Name.TrimToFitColumn(),
Key = f.Key.TrimToFitColumn(),
Hint = f.Hint.TrimToFitColumn(),
Type = f.SettingType,
Tags = $"[{string.Join(", ", f.Tags.Select(t => $"{t.Name} ({t.TagId})"))}]",
Owner = $"{f.OwnerUserFullName} [{f.OwnerUserEmail}]",
Owner = $"{f.CreatorFullName} [{f.CreatorEmail}]",
Config = $"{f.ConfigName} [{f.ConfigId}]",
});
output.RenderTable(itemsToRender);
Expand Down
27 changes: 5 additions & 22 deletions src/ConfigCat.Cli/Commands/Flags/FlagValue.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using ConfigCat.Cli.Models.Api;
using ConfigCat.Cli.Services;
using ConfigCat.Cli.Services;
using ConfigCat.Cli.Services.Api;
using ConfigCat.Cli.Services.Exceptions;
using ConfigCat.Cli.Services.Json;
Expand All @@ -9,6 +8,7 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using ConfigCat.Cli.Models;

namespace ConfigCat.Cli.Commands.Flags;

Expand Down Expand Up @@ -37,6 +37,9 @@ public async Task<int> ShowValueAsync(int? flagId, bool json, CancellationToken
foreach (var environment in environments)
{
var value = await flagValueClient.GetValueAsync(flag.SettingId, environment.EnvironmentId, token);
flag.CreatorEmail ??= value.Setting.CreatorEmail;
flag.CreatorFullName ??= value.Setting.CreatorFullName;
flag.CreatedAt ??= value.Setting.CreatedAt;
valuesInJson.Add(new ValueInEnvironmentJsonOutput
{
EnvironmentId = environment.EnvironmentId,
Expand Down Expand Up @@ -167,23 +170,3 @@ public async Task<int> UpdateFlagValueAsync(int? flagId, string environmentId, s
return ExitCodes.Ok;
}
}

internal class FlagValueJsonOutput
{
public FlagModel Setting { get; set; }

public IEnumerable<ValueInEnvironmentJsonOutput> Values { get; set; }
}

internal class ValueInEnvironmentJsonOutput
{
public string EnvironmentId { get; set; }

public string EnvironmentName { get; set; }

public List<PercentageModel> PercentageRules { get; set; }

public List<TargetingModel> TargetingRules { get; set; }

public object Value { get; set; }
}
19 changes: 2 additions & 17 deletions src/ConfigCat.Cli/Commands/Flags/V2/FlagValue.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using ConfigCat.Cli.Models.Api;
using ConfigCat.Cli.Services;
using ConfigCat.Cli.Services;
using ConfigCat.Cli.Services.Api;
using ConfigCat.Cli.Services.Exceptions;
using ConfigCat.Cli.Services.Json;
Expand All @@ -9,6 +8,7 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using ConfigCat.Cli.Models;
using ConfigCat.Cli.Services.Extensions;

namespace ConfigCat.Cli.Commands.Flags.V2;
Expand Down Expand Up @@ -255,19 +255,4 @@ public async Task<int> UpdateFlagValueAsync(int? flagId, string environmentId, s
await flagValueClient.UpdateValueAsync(flag.SettingId, environmentId, reason, jsonPatchDocument.Operations, token);
return ExitCodes.Ok;
}
}

internal class FlagValueV2JsonOutput
{
public FlagModel Setting { get; set; }
public IEnumerable<ValueV2InEnvironmentJsonOutput> Values { get; set; }
}

internal class ValueV2InEnvironmentJsonOutput
{
public string EnvironmentId { get; set; }
public string EnvironmentName { get; set; }
public ValueModel DefaultValue { get; set; }
public List<TargetingRuleModel> TargetingRules { get; set; }
public string PercentageEvaluationAttribute { get; set; }
}
8 changes: 1 addition & 7 deletions src/ConfigCat.Cli/Commands/ListAll.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using ConfigCat.Cli.Models;

namespace ConfigCat.Cli.Commands;

Expand Down Expand Up @@ -70,11 +71,4 @@ private class ConfigEnvironment

public EnvironmentModel Environment { get; set; }
}

private class ProductJsonOutput : ProductModel
{
public IEnumerable<EnvironmentModel> Environments { get; set; }

public IEnumerable<ConfigModel> Configs { get; set; }
}
}

0 comments on commit 1e26d0c

Please sign in to comment.