Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -38,13 +39,14 @@
subcommands = {
InfoCommand.class,
GetCommand.class,
GetAllCommand.class,
RemoveCommand.class
})
@Slf4j
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'");
}
}
Original file line number Diff line number Diff line change
@@ -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
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #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<String> 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");
}

}