diff --git a/cms-server/src/main/java/com/condation/cms/cli/commands/ThemeCommands.java b/cms-server/src/main/java/com/condation/cms/cli/commands/ThemeCommands.java index 8fd1040f0..c0f66cbed 100644 --- a/cms-server/src/main/java/com/condation/cms/cli/commands/ThemeCommands.java +++ b/cms-server/src/main/java/com/condation/cms/cli/commands/ThemeCommands.java @@ -23,6 +23,7 @@ */ +import com.condation.cms.cli.commands.themes.GetAllCommand; import com.condation.cms.cli.commands.themes.GetCommand; import com.condation.cms.cli.commands.themes.InfoCommand; import com.condation.cms.cli.commands.themes.RemoveCommand; @@ -38,6 +39,7 @@ subcommands = { InfoCommand.class, GetCommand.class, + GetAllCommand.class, RemoveCommand.class }) @Slf4j @@ -45,6 +47,6 @@ public class ThemeCommands implements Runnable { @Override public void run() { - System.out.println("Subcommand needed: 'get', 'remove' or 'info'"); + System.out.println("Subcommand needed: 'get', 'get-all', 'remove' or 'info'"); } } diff --git a/cms-server/src/main/java/com/condation/cms/cli/commands/themes/GetAllCommand.java b/cms-server/src/main/java/com/condation/cms/cli/commands/themes/GetAllCommand.java new file mode 100644 index 000000000..8fbafb214 --- /dev/null +++ b/cms-server/src/main/java/com/condation/cms/cli/commands/themes/GetAllCommand.java @@ -0,0 +1,79 @@ +package com.condation.cms.cli.commands.themes; + +/*- + * #%L + * cms-server + * %% + * Copyright (C) 2023 - 2024 CondationCMS + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * #L% + */ + + +import com.condation.cms.cli.tools.ThemesUtil; +import com.condation.cms.extensions.repository.InstallationHelper; +import com.google.common.base.Strings; +import java.nio.file.Path; +import java.util.Set; +import lombok.extern.slf4j.Slf4j; +import picocli.CommandLine; + +/** + * + * @author t.marx + */ +@Slf4j +@CommandLine.Command(name = "get-all") +public class GetAllCommand extends AbstractThemeCommand implements Runnable { + + @CommandLine.Option(names = "-f", description = "force the update if theme is already installed") + boolean forceUpdate; + + @Override + public void run () { + Set themes = ThemesUtil.getRequiredThemes(); + + themes.forEach(this::getTheme); + } + + public void getTheme(String theme) { + if (!getRepository().exists(theme)) { + System.err.printf("Theme %s not found\r\n", theme); + return; + } + + if (!isCompatibleWithServer(theme)) { + System.err.println("theme is not compatible with server version"); + return; + } + + if (isInstalled(theme) && !forceUpdate) { + System.err.println("theme is already installed, use -f to force an update"); + return; + } + + if (isInstalled(theme)) { + InstallationHelper.deleteDirectory(getThemeFolder(theme).toFile()); + } + + var info = getRepository().getInfo(theme).get(); + + System.out.println("get theme"); + getRepository().download(info.getFile(), Path.of("themes/")); + System.out.println("theme downloaded"); + } + +}