diff --git a/cli/Squidex.CLI/Squidex.CLI/Commands/App.cs b/cli/Squidex.CLI/Squidex.CLI/Commands/App.cs index b7cc43bb..b9ba3cad 100644 --- a/cli/Squidex.CLI/Squidex.CLI/Commands/App.cs +++ b/cli/Squidex.CLI/Squidex.CLI/Commands/App.cs @@ -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; } + } } } diff --git a/cli/Squidex.CLI/Squidex.CLI/Commands/App_Apps.cs b/cli/Squidex.CLI/Squidex.CLI/Commands/App_Apps.cs index 3ea48ca4..38d5c8d2 100644 --- a/cli/Squidex.CLI/Squidex.CLI/Commands/App_Apps.cs +++ b/cli/Squidex.CLI/Squidex.CLI/Commands/App_Apps.cs @@ -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(); @@ -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)) { @@ -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; } @@ -90,11 +90,8 @@ public sealed class Validator : AbstractValidator } [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 { } diff --git a/cli/Squidex.CLI/Squidex.CLI/Commands/App_Assets.cs b/cli/Squidex.CLI/Squidex.CLI/Commands/App_Assets.cs index 44d1d650..8e9e6f37 100644 --- a/cli/Squidex.CLI/Squidex.CLI/Commands/App_Assets.cs +++ b/cli/Squidex.CLI/Squidex.CLI/Commands/App_Assets.cs @@ -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; @@ -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; @@ -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; } @@ -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; } diff --git a/cli/Squidex.CLI/Squidex.CLI/Commands/App_Backup.cs b/cli/Squidex.CLI/Squidex.CLI/Commands/App_Backup.cs index 1d85c1d3..6295325d 100644 --- a/cli/Squidex.CLI/Squidex.CLI/Commands/App_Backup.cs +++ b/cli/Squidex.CLI/Squidex.CLI/Commands/App_Backup.cs @@ -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); @@ -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; } diff --git a/cli/Squidex.CLI/Squidex.CLI/Commands/App_Content.cs b/cli/Squidex.CLI/Squidex.CLI/Commands/App_Content.cs index bce92da4..722d8c0d 100644 --- a/cli/Squidex.CLI/Squidex.CLI/Commands/App_Content.cs +++ b/cli/Squidex.CLI/Squidex.CLI/Commands/App_Content.cs @@ -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); @@ -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) { @@ -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) { @@ -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; } @@ -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; } @@ -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; } diff --git a/cli/Squidex.CLI/Squidex.CLI/Commands/App_OpenLibrary.cs b/cli/Squidex.CLI/Squidex.CLI/Commands/App_OpenLibrary.cs index d0979a2c..8d64d578 100644 --- a/cli/Squidex.CLI/Squidex.CLI/Commands/App_OpenLibrary.cs +++ b/cli/Squidex.CLI/Squidex.CLI/Commands/App_OpenLibrary.cs @@ -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 { @@ -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)) { @@ -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 + { + } + } + + [Validator(typeof(Validator))] + public sealed class ImportArguments : AppArguments { [Operand(Name = "file", Description = "The data dump file.")] public string File { get; set; } diff --git a/cli/Squidex.CLI/Squidex.CLI/Commands/App_Schemas.cs b/cli/Squidex.CLI/Squidex.CLI/Commands/App_Schemas.cs index 40c3c926..c33cbaa0 100644 --- a/cli/Squidex.CLI/Squidex.CLI/Commands/App_Schemas.cs +++ b/cli/Squidex.CLI/Squidex.CLI/Commands/App_Schemas.cs @@ -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); @@ -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); @@ -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; @@ -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; } @@ -178,7 +178,7 @@ public sealed class Validator : AbstractValidator } [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; } @@ -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; } diff --git a/cli/Squidex.CLI/Squidex.CLI/Commands/App_Sync.cs b/cli/Squidex.CLI/Squidex.CLI/Commands/App_Sync.cs index 9cec237d..53804fb5 100644 --- a/cli/Squidex.CLI/Squidex.CLI/Commands/App_Sync.cs +++ b/cli/Squidex.CLI/Squidex.CLI/Commands/App_Sync.cs @@ -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); @@ -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); @@ -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; } @@ -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; } @@ -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; } diff --git a/cli/Squidex.CLI/Squidex.CLI/Commands/App_Twitter.cs b/cli/Squidex.CLI/Squidex.CLI/Commands/App_Twitter.cs index 885c6529..d19aec56 100644 --- a/cli/Squidex.CLI/Squidex.CLI/Commands/App_Twitter.cs +++ b/cli/Squidex.CLI/Squidex.CLI/Commands/App_Twitter.cs @@ -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"; @@ -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; } diff --git a/cli/Squidex.CLI/Squidex.CLI/Commands/Implementation/Sync/Schemas/SchemasSynchronizer.cs b/cli/Squidex.CLI/Squidex.CLI/Commands/Implementation/Sync/Schemas/SchemasSynchronizer.cs index 15895eed..a6aa22e9 100644 --- a/cli/Squidex.CLI/Squidex.CLI/Commands/Implementation/Sync/Schemas/SchemasSynchronizer.cs +++ b/cli/Squidex.CLI/Squidex.CLI/Commands/Implementation/Sync/Schemas/SchemasSynchronizer.cs @@ -216,21 +216,36 @@ private static void MapReferences(FieldPropertiesDto properties, Dictionary(); + 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 MapReferences(List ids, Dictionary map) + { + if (ids == null || ids.Count == 0) + { + return ids; + } - references.SchemaIds = names; + var result = new List(); + + foreach (var id in ids) + { + if (map.TryGetValue(id, out var target)) + { + result.Add(target); } } + + return result; } } } diff --git a/cli/Squidex.CLI/Squidex.CLI/Commands/Implementation/Sync/Synchronizer.cs b/cli/Squidex.CLI/Squidex.CLI/Commands/Implementation/Sync/Synchronizer.cs index 95c1767c..56a62590 100644 --- a/cli/Squidex.CLI/Squidex.CLI/Commands/Implementation/Sync/Synchronizer.cs +++ b/cli/Squidex.CLI/Squidex.CLI/Commands/Implementation/Sync/Synchronizer.cs @@ -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); @@ -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); @@ -96,9 +96,9 @@ await selectedSynchronizers.Foreach(async (synchronizer, step) => } } - private void WriteSummary(IFileSystem fs, List selectedSynchronizers) + private void WriteSummary(IFileSystem fs, ISession session, string direction, List 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"); diff --git a/cli/Squidex.CLI/Squidex.CLI/Configuration/ConfigurationService.cs b/cli/Squidex.CLI/Squidex.CLI/Configuration/ConfigurationService.cs index 80f55346..f4e22d7c 100644 --- a/cli/Squidex.CLI/Squidex.CLI/Configuration/ConfigurationService.cs +++ b/cli/Squidex.CLI/Squidex.CLI/Configuration/ConfigurationService.cs @@ -20,7 +20,6 @@ public sealed class ConfigurationService : IConfigurationService private const string CloudUrl = "https://cloud.squidex.io"; private readonly JsonSerializer jsonSerializer = new JsonSerializer(); private readonly Configuration configuration; - private string sessionApp; public ConfigurationService() { @@ -126,14 +125,9 @@ public void Remove(string entry) Save(); } - public void UseAppInSession(string entry) + public ISession StartSession(string appName, bool emulate = false) { - sessionApp = entry; - } - - public ISession StartSession(bool emulate = false) - { - if (!string.IsNullOrWhiteSpace(sessionApp) && configuration.Apps.TryGetValue(sessionApp, out var app)) + if (!string.IsNullOrWhiteSpace(appName) && configuration.Apps.TryGetValue(appName, out var app)) { var options = CreateOptions(app, emulate); diff --git a/cli/Squidex.CLI/Squidex.CLI/Configuration/IConfigurationService.cs b/cli/Squidex.CLI/Squidex.CLI/Configuration/IConfigurationService.cs index af1a6d4f..6579fae2 100644 --- a/cli/Squidex.CLI/Squidex.CLI/Configuration/IConfigurationService.cs +++ b/cli/Squidex.CLI/Squidex.CLI/Configuration/IConfigurationService.cs @@ -21,8 +21,6 @@ public interface IConfigurationService void UseApp(string entry); - void UseAppInSession(string entry); - - ISession StartSession(bool emulate = false); + ISession StartSession(string app, bool emulate = false); } }