Skip to content

Commit

Permalink
Another CLI fix for components.
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianStehle committed Nov 14, 2021
1 parent 2c4968b commit 61dc1ef
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 63 deletions.
6 changes: 6 additions & 0 deletions cli/Squidex.CLI/Squidex.CLI/Commands/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,11 @@ public void Info()

log.WriteLine($"Squidex CLI v{version}, API Compatibility >= 4.X");
}

public abstract class AppArguments : IArgumentModel
{
[Option(LongName = "app", Description = "The name of the app. If not provided then app configured in currentApp gets created.")]
public string App { get; set; }
}
}
}
13 changes: 5 additions & 8 deletions cli/Squidex.CLI/Squidex.CLI/Commands/App_Apps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public Apps(IConfigurationService configuration, ILogger log)
[Command(Name = "list", Description = "List all schemas.")]
public async Task List(ListArguments arguments)
{
var session = configuration.StartSession();
var session = configuration.StartSession(arguments.App);

var apps = await session.Apps.GetAppsAsync();

Expand All @@ -59,9 +59,9 @@ public async Task List(ListArguments arguments)
[Command(Name = "create", Description = "Creates a squidex app.")]
public async Task Create(CreateArguments arguments)
{
var session = configuration.StartSession();
var session = configuration.StartSession(arguments.App);

var name = arguments.Name;
var name = arguments.App;

if (string.IsNullOrWhiteSpace(name))
{
Expand All @@ -79,7 +79,7 @@ public async Task Create(CreateArguments arguments)
}

[Validator(typeof(Validator))]
public sealed class ListArguments : IArgumentModel
public sealed class ListArguments : AppArguments
{
[Option(LongName = "table", ShortName = "t", Description = "Output as table")]
public bool Table { get; set; }
Expand All @@ -90,11 +90,8 @@ public sealed class Validator : AbstractValidator<ListArguments>
}

[Validator(typeof(Validator))]
public sealed class CreateArguments : IArgumentModel
public sealed class CreateArguments : AppArguments
{
[Operand(Name = "name", Description = "The name of the app. If not provided then app configured in currentApp gets created.")]
public string Name { get; set; }

public sealed class Validator : AbstractValidator<CreateArguments>
{
}
Expand Down
8 changes: 4 additions & 4 deletions cli/Squidex.CLI/Squidex.CLI/Commands/App_Assets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public Assets(IConfigurationService configuration, ILogger log)
[Command(Name = "import", Description = "Import all files from the source folder.")]
public async Task Import(ImportArguments arguments)
{
var session = configuration.StartSession();
var session = configuration.StartSession(arguments.App);

var assets = session.Assets;

Expand Down Expand Up @@ -120,7 +120,7 @@ public async Task Import(ImportArguments arguments)
[Command(Name = "export", Description = "Export all files to the source folder.")]
public async Task Export(ImportArguments arguments)
{
var session = configuration.StartSession();
var session = configuration.StartSession(arguments.App);

var assets = session.Assets;

Expand Down Expand Up @@ -173,7 +173,7 @@ await assets.GetAllByQueryAsync(session.App, async asset =>
}

[Validator(typeof(Validator))]
public sealed class ImportArguments : IArgumentModel
public sealed class ImportArguments : AppArguments
{
[Operand(Name = "folder", Description = "The source folder.")]
public string Path { get; set; }
Expand All @@ -194,7 +194,7 @@ public Validator()
}

[Validator(typeof(Validator))]
public sealed class ExportArguments : IArgumentModel
public sealed class ExportArguments : AppArguments
{
[Operand(Name = "folder", Description = "The source folder.")]
public string Path { get; set; }
Expand Down
4 changes: 2 additions & 2 deletions cli/Squidex.CLI/Squidex.CLI/Commands/App_Backup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public Backup(IConfigurationService configuration, ILogger log)
[Command(Name = "create", Description = "Create and download an backup.")]
public async Task Create(CreateArguments arguments)
{
var session = configuration.StartSession();
var session = configuration.StartSession(arguments.App);

var backupStarted = DateTime.UtcNow.AddMinutes(-5);

Expand Down Expand Up @@ -97,7 +97,7 @@ public async Task Create(CreateArguments arguments)
}

[Validator(typeof(Validator))]
public sealed class CreateArguments : IArgumentModel
public sealed class CreateArguments: AppArguments
{
[Operand(Name = "file", Description = "The target file.")]
public string File { get; set; }
Expand Down
12 changes: 6 additions & 6 deletions cli/Squidex.CLI/Squidex.CLI/Commands/App_Content.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public Content(IConfigurationService configuration, ILogger log)
[Command(Name = "test-data", Description = "Generates test data.")]
public async Task TestData(TestDataArguments arguments)
{
var session = configuration.StartSession();
var session = configuration.StartSession(arguments.App);

var taskForSchema = session.Schemas.GetSchemaAsync(session.App, arguments.Schema);
var taskForLanguages = session.Apps.GetLanguagesAsync(session.App);
Expand Down Expand Up @@ -88,7 +88,7 @@ await Task.WhenAll(
")]
public async Task Import(ImportArguments arguments)
{
var session = configuration.StartSession();
var session = configuration.StartSession(arguments.App);

if (arguments.Format == Format.JSON)
{
Expand Down Expand Up @@ -141,7 +141,7 @@ public async Task Import(ImportArguments arguments)
")]
public async Task Export(ExportArguments arguments)
{
var session = configuration.StartSession();
var session = configuration.StartSession(arguments.App);

string OpenFile(string extension)
{
Expand Down Expand Up @@ -291,7 +291,7 @@ public enum Format
}

[Validator(typeof(Validator))]
public sealed class ImportArguments : IImportSettings, IArgumentModel
public sealed class ImportArguments : AppArguments, IImportSettings
{
[Operand(Name = "schema", Description = "The name of the schema.")]
public string Schema { get; set; }
Expand Down Expand Up @@ -328,7 +328,7 @@ public Validator()
}

[Validator(typeof(Validator))]
public sealed class ExportArguments : IExportSettings, IArgumentModel
public sealed class ExportArguments : AppArguments, IExportSettings
{
[Operand(Name = "schema", Description = "The name of the schema.")]
public string Schema { get; set; }
Expand Down Expand Up @@ -379,7 +379,7 @@ public Validator()
}

[Validator(typeof(Validator))]
public sealed class TestDataArguments : IImportSettings, IArgumentModel
public sealed class TestDataArguments : AppArguments, IImportSettings
{
[Operand(Name = "schema", Description = "The name of the schema.")]
public string Schema { get; set; }
Expand Down
16 changes: 12 additions & 4 deletions cli/Squidex.CLI/Squidex.CLI/Commands/App_OpenLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public OpenLibrary(IConfigurationService configuration, Synchronizer synchronize
}

[Command(Name = "generate", Description = "Generate the necessary schemas.")]
public async Task New()
public async Task New(NewArguments arguments)
{
var session = configuration.StartSession();
var session = configuration.StartSession(arguments.App);

await synchronizer.ImportAsync("assembly://Squidex.CLI.Commands.Implementation.OpenLibrary.Structure", new SyncOptions
{
Expand All @@ -55,7 +55,7 @@ public async Task New()
[Command(Name = "authors", Description = "Import the authors.")]
public async Task Authors(ImportArguments arguments)
{
var session = configuration.StartSession();
var session = configuration.StartSession(arguments.App);

using (var stream = new FileStream(arguments.File, FileMode.Open))
{
Expand All @@ -68,7 +68,15 @@ public async Task Authors(ImportArguments arguments)
}

[Validator(typeof(Validator))]
public sealed class ImportArguments : IArgumentModel
public sealed class NewArguments : AppArguments
{
public sealed class Validator : AbstractValidator<NewArguments>
{
}
}

[Validator(typeof(Validator))]
public sealed class ImportArguments : AppArguments
{
[Operand(Name = "file", Description = "The data dump file.")]
public string File { get; set; }
Expand Down
12 changes: 6 additions & 6 deletions cli/Squidex.CLI/Squidex.CLI/Commands/App_Schemas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public Schemas(IConfigurationService configuration, ILogger log)
[Command(Name = "list", Description = "List all schemas.")]
public async Task List(ListArguments arguments)
{
var session = configuration.StartSession();
var session = configuration.StartSession(arguments.App);

var schemas = await session.Schemas.GetSchemasAsync(session.App);

Expand All @@ -65,7 +65,7 @@ public async Task List(ListArguments arguments)
[Command(Name = "get", Description = "Get a schema by name.")]
public async Task Get(GetArguments arguments)
{
var session = configuration.StartSession();
var session = configuration.StartSession(arguments.App);

var schema = await session.Schemas.GetSchemaAsync(session.App, arguments.Name);

Expand All @@ -86,7 +86,7 @@ public async Task Get(GetArguments arguments)
[Command(Name = "sync", Description = "Sync the schema.")]
public async Task Sync(SyncArguments arguments)
{
var session = configuration.StartSession();
var session = configuration.StartSession(arguments.App);

var schemaText = string.Empty;
var schemaName = arguments.Name;
Expand Down Expand Up @@ -167,7 +167,7 @@ public async Task Sync(SyncArguments arguments)
}

[Validator(typeof(Validator))]
public sealed class ListArguments : IArgumentModel
public sealed class ListArguments : AppArguments
{
[Option(LongName = "table", ShortName = "t", Description = "Output as table")]
public bool Table { get; set; }
Expand All @@ -178,7 +178,7 @@ public sealed class Validator : AbstractValidator<ListArguments>
}

[Validator(typeof(Validator))]
public sealed class GetArguments : IArgumentModel
public sealed class GetArguments : AppArguments
{
[Operand(Name = "name", Description = "The name of the schema.")]
public string Name { get; set; }
Expand All @@ -196,7 +196,7 @@ public Validator()
}

[Validator(typeof(Validator))]
public sealed class SyncArguments : IArgumentModel
public sealed class SyncArguments : AppArguments
{
[Operand(Name = "file", Description = "The file with the schema json.")]
public string File { get; set; }
Expand Down
10 changes: 5 additions & 5 deletions cli/Squidex.CLI/Squidex.CLI/Commands/App_Sync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public async Task New(NewArgument arguments)
[Command(Name = "out", Description = "Exports the app to a folder")]
public async Task Out(OutArguments arguments)
{
var session = configuration.StartSession();
var session = configuration.StartSession(arguments.App);

await synchronizer.ExportAsync(arguments.Folder, arguments.ToOptions(), session);

Expand All @@ -54,7 +54,7 @@ public async Task Out(OutArguments arguments)
[Command(Name = "in", Description = "Imports the app from a folder")]
public async Task In(InArguments arguments)
{
var session = configuration.StartSession(arguments.Emulate);
var session = configuration.StartSession(arguments.App, arguments.Emulate);

await synchronizer.ImportAsync(arguments.Folder, arguments.ToOptions(), session);

Expand All @@ -71,7 +71,7 @@ public void Targets()
}

[Validator(typeof(Validator))]
public sealed class NewArgument : IArgumentModel
public sealed class NewArgument : AppArguments
{
[Operand(Name = "folder", Description = "The target folder to create the templates.")]
public string Folder { get; set; }
Expand All @@ -86,7 +86,7 @@ public Validator()
}

[Validator(typeof(Validator))]
public sealed class InArguments : IArgumentModel
public sealed class InArguments : AppArguments
{
[Operand(Name = "folder", Description = "The target folder to synchronize.")]
public string Folder { get; set; }
Expand Down Expand Up @@ -118,7 +118,7 @@ public Validator()
}

[Validator(typeof(Validator))]
public sealed class OutArguments : IArgumentModel
public sealed class OutArguments : AppArguments
{
[Operand(Name = "folder", Description = "The target folder to synchronize.")]
public string Folder { get; set; }
Expand Down
4 changes: 2 additions & 2 deletions cli/Squidex.CLI/Squidex.CLI/Commands/App_Twitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private string ReadToken(string fromArgs, string file, string parameter)
}

[Validator(typeof(Validator))]
public sealed class AuthArguments : IArgumentModel
public sealed class AuthArguments : AppArguments
{
[Option(LongName = "clientId")]
public string ClientId { get; set; } = "QZhb3HQcGCvE6G8yNNP9ksNet";
Expand All @@ -107,7 +107,7 @@ public Validator()
}

[Validator(typeof(Validator))]
public sealed class TokenArguments : IArgumentModel
public sealed class TokenArguments : AppArguments
{
[Operand(Name = "pin", Description = "The pin from the auth request.")]
public string PinCode { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,21 +216,36 @@ private static void MapReferences(FieldPropertiesDto properties, Dictionary<stri
{
if (properties is ReferencesFieldPropertiesDto references)
{
if (references.SchemaIds != null && references.SchemaIds.Any())
{
var names = new List<string>();
references.SchemaIds = MapReferences(references.SchemaIds, map);
}
else if (properties is ComponentFieldPropertiesDto component)
{
component.SchemaIds = MapReferences(component.SchemaIds, map);
}
else if (properties is ComponentsFieldPropertiesDto components)
{
components.SchemaIds = MapReferences(components.SchemaIds, map);
}
}

foreach (var id in references.SchemaIds)
{
if (map.TryGetValue(id, out var target))
{
names.Add(target);
}
}
private static List<string> MapReferences(List<string> ids, Dictionary<string, string> map)
{
if (ids == null || ids.Count == 0)
{
return ids;
}

references.SchemaIds = names;
var result = new List<string>();

foreach (var id in ids)
{
if (map.TryGetValue(id, out var target))
{
result.Add(target);
}
}

return result;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public async Task ExportAsync(string path, SyncOptions options, ISession session
var selectedSynchronizers = GetSynchronizers(options.Targets);
var selectedCount = selectedSynchronizers.Count;

WriteSummary(fs, selectedSynchronizers);
WriteSummary(fs, session, "->", selectedSynchronizers);

var sync = new SyncService(fs);

Expand Down Expand Up @@ -76,7 +76,7 @@ public async Task ImportAsync(string path, SyncOptions options, ISession session
var selectedSynchronizers = GetSynchronizers(options.Targets);
var selectedCount = selectedSynchronizers.Count;

WriteSummary(fs, selectedSynchronizers);
WriteSummary(fs, session, "<-", selectedSynchronizers);

var sync = new SyncService(fs);

Expand All @@ -96,9 +96,9 @@ await selectedSynchronizers.Foreach(async (synchronizer, step) =>
}
}

private void WriteSummary(IFileSystem fs, List<ISynchronizer> selectedSynchronizers)
private void WriteSummary(IFileSystem fs, ISession session, string direction, List<ISynchronizer> selectedSynchronizers)
{
log.WriteLine("Synchronizing from {0}", fs.FullName);
log.WriteLine("Synchronizing app:'{0}' {1} {2}", session.App, direction, fs.FullName);
log.WriteLine();
log.WriteLine("Executing the following steps");

Expand Down
Loading

0 comments on commit 61dc1ef

Please sign in to comment.