Skip to content

Commit

Permalink
cli-v13.5
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianStehle committed Nov 9, 2024
1 parent 217915b commit a7bd6d7
Show file tree
Hide file tree
Showing 14 changed files with 217 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public Task DescribeAsync(ISyncService sync, MarkdownWriter writer)

writer.H3("Clients");
writer.Paragraph($"{rows.Length} client(s).");
writer.Table(new[] { "Name", "Label", "Role" }, rows);
writer.Table(["Name", "Label", "Role"], rows);
}

if (model.Roles.Count > 0)
Expand All @@ -109,7 +109,7 @@ public Task DescribeAsync(ISyncService sync, MarkdownWriter writer)

writer.H3("Roles");
writer.Paragraph($"{rows.Length} role(s).");
writer.Table(new[] { "Name", "Permissions" }, rows);
writer.Table(["Name", "Permissions"], rows);
}

if (model.Contributors.Count > 0)
Expand All @@ -118,7 +118,7 @@ public Task DescribeAsync(ISyncService sync, MarkdownWriter writer)

writer.H3("Contributors");
writer.Paragraph($"{rows.Length} contributor(s).");
writer.Table(new[] { "Id", "Role" }, rows);
writer.Table(["Id", "Role"], rows);
}

if (model.Languages.Count > 0)
Expand All @@ -127,7 +127,7 @@ public Task DescribeAsync(ISyncService sync, MarkdownWriter writer)

writer.H3("Languages");
writer.Paragraph($"{rows.Length} language(s).");
writer.Table(new[] { "Code", "Master" }, rows);
writer.Table(["Code", "Master"], rows);
}

return Task.CompletedTask;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ await client.GetAllAsync(async content =>
return;
}

// Convert schema IDs to schema names.
content.MapComponents(schemaMap);

contents.Add(content.ToModel(schema.Name));
Expand Down Expand Up @@ -120,7 +121,7 @@ public Task DescribeAsync(ISyncService sync, MarkdownWriter writer)

if (rows.Length > 0)
{
writer.Table(new[] { "Schema", "Counts" }, rows);
writer.Table(["Schema", "Counts"], rows);
}

return Task.CompletedTask;
Expand Down Expand Up @@ -153,7 +154,7 @@ public async Task ImportAsync(ISyncService sync, SyncOptions options, ISession s
DoNotScript = true,
DoNotValidate = false,
DoNotValidateWorkflow = true,
Jobs = model.Contents.Select(x => x.ToUpsert(schemas, options.ContentAction)).ToList()
Jobs = model.Contents.Select(x => x.ToUpsert(schemas, schemaMap, options.ContentAction)).ToList()
};

var contentIdAssigned = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ namespace Squidex.CLI.Commands.Implementation.Sync.Contents;

internal static class Extensions
{
public static BulkUpdateJob ToUpsert(this ContentModel model, SchemasDto schemas, ContentAction action)
public static BulkUpdateJob ToUpsert(this ContentModel model,
SchemasDto schemas,
Dictionary<string, string> schemasMap,
ContentAction action)
{
var result = SimpleMapper.Map(model, new BulkUpdateJob());

Expand All @@ -25,6 +28,9 @@ public static BulkUpdateJob ToUpsert(this ContentModel model, SchemasDto schemas
result.Id = singleton.Id;
}

// Convert schema names back to IDs.
model.MapComponents(schemasMap);

switch (action)
{
case ContentAction.UpsertPatch:
Expand All @@ -42,7 +48,6 @@ public static BulkUpdateJob ToUpsert(this ContentModel model, SchemasDto schemas
}

result.Data = model.Data;

return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public Task DescribeAsync(ISyncService sync, MarkdownWriter writer)
{
var rows = models.Select(x => new object[] { x.Name, x.Trigger.TypeName(), x.Action.TypeName() }).OrderBy(x => x[0]).ToArray();

writer.Table(new[] { "Name", "Trigger", "Action" }, rows);
writer.Table(["Name", "Trigger", "Action"], rows);
}

return Task.CompletedTask;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public Task DescribeAsync(ISyncService sync, MarkdownWriter writer)
{
var rows = models.Select(x => new object[] { x.Name, x.SchemaType.ToString(), x.Schema.Fields.Count }).OrderBy(x => x[0]).ToArray();

writer.Table(new[] { "Schema", "Type", "Fields" }, rows);
writer.Table(["Schema", "Type", "Fields"], rows);
}

return Task.CompletedTask;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public Task DescribeAsync(ISyncService sync, MarkdownWriter writer)
{
var rows = models.Select(x => new object[] { x.Name, string.Join(", ", x.Steps.Select(y => y.Key)), x.Initial }).OrderBy(x => x[0]).ToArray();

writer.Table(new[] { "Name", "Steps", "Initial" }, rows);
writer.Table(["Name", "Steps", "Initial"], rows);
}

return Task.CompletedTask;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static class LoremIpsum
private const int SentencesPerParagraph = 3;

private static readonly string[] Words =
{
[
"lorem",
"ipsum",
"dolor",
Expand All @@ -35,7 +35,7 @@ public static class LoremIpsum
"magna",
"aliquam",
"erat"
};
];

public static string GetWord(Random random)
{
Expand Down
2 changes: 1 addition & 1 deletion cli/Squidex.CLI/Squidex.CLI/Commands/App_Assets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public async Task Import(ImportArguments arguments)

log.WriteLine($"Uploading: {file.FullName}");

if (existings.Items.Any(x => string.Equals(x.FileHash, fileHash, StringComparison.Ordinal)))
if (existings.Items.Exists(x => string.Equals(x.FileHash, fileHash, StringComparison.Ordinal)))
{
log.StepSkipped("Same hash.");
}
Expand Down
28 changes: 14 additions & 14 deletions cli/Squidex.CLI/Squidex.CLI/Commands/App_Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ public void List(ListArguments arguments)
[Command("add", Description = "Add or update an app.")]
public void Add(AddArguments arguments)
{
var entry = !string.IsNullOrWhiteSpace(arguments.Label) ? arguments.Label : arguments.Name;
var entry = !string.IsNullOrWhiteSpace(arguments.Label) ? arguments.Label : arguments.App;

var appConfig = new ConfiguredApp
{
Name = arguments.Name,
Name = arguments.App,
ClientId = arguments.ClientId,
ClientSecret = arguments.ClientSecret,
IgnoreSelfSigned = arguments.IgnoreSelfSigned,
Expand All @@ -63,7 +63,7 @@ public void Add(AddArguments arguments)

if (arguments.Use)
{
configuration.UseApp(arguments.Name);
configuration.UseApp(arguments.App);

log.Completed("App added and selected.");
}
Expand All @@ -76,15 +76,15 @@ public void Add(AddArguments arguments)
[Command("use", Description = "Use an app.")]
public void Use(UseArguments arguments)
{
configuration.UseApp(arguments.Name);
configuration.UseApp(arguments.App);

log.Completed("App selected.");
}

[Command("remove", Description = "Remove an app.")]
public void Remove(RemoveArguments arguments)
{
configuration.Remove(arguments.Name);
configuration.Remove(arguments.App);

log.Completed("App removed.");
}
Expand All @@ -109,36 +109,36 @@ public sealed class Validator : AbstractValidator<ListArguments>

public sealed class RemoveArguments : IArgumentModel
{
[Operand("name", Description = "The name of the app.")]
public string Name { get; set; }
[Operand("app", Description = "The name of the app.")]
public string App { get; set; }

public sealed class Validator : AbstractValidator<RemoveArguments>
{
public Validator()
{
RuleFor(x => x.Name).NotEmpty();
RuleFor(x => x.App).NotEmpty();
}
}
}

public sealed class UseArguments : IArgumentModel
{
[Operand("name", Description = "The name of the app.")]
public string Name { get; set; }
[Operand("app", Description = "The name of the app.")]
public string App { get; set; }

public sealed class Validator : AbstractValidator<UseArguments>
{
public Validator()
{
RuleFor(x => x.Name).NotEmpty();
RuleFor(x => x.App).NotEmpty();
}
}
}

public sealed class AddArguments : IArgumentModel
{
[Operand("name", Description = "The name of the app.")]
public string Name { get; set; }
[Operand("app", Description = "The name of the app.")]
public string App { get; set; }

[Operand("client-id", Description = "The client id.")]
public string ClientId { get; set; }
Expand All @@ -165,7 +165,7 @@ public sealed class Validator : AbstractValidator<AddArguments>
{
public Validator()
{
RuleFor(x => x.Name).NotEmpty();
RuleFor(x => x.App).NotEmpty();
RuleFor(x => x.ClientId).NotEmpty();
RuleFor(x => x.ClientSecret).NotEmpty();
}
Expand Down
Loading

0 comments on commit a7bd6d7

Please sign in to comment.