Skip to content

Commit

Permalink
fix short commands
Browse files Browse the repository at this point in the history
  • Loading branch information
slavaWins committed Feb 23, 2024
1 parent af2b1d6 commit fe890ab
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 48 deletions.
27 changes: 17 additions & 10 deletions lang/en.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
{
"process": "Process: ",
"up.build": "Building namespace ",
"helpcom": "Command help:",
"up.all": "Launching namespace ",
"ns.not": "Namespace not found ",
"com.ns": "Show all namespaces",
"notfoundcomand": "Command not found!",
"com.help": "Help",
"app.stopping": "A safe stop of the application has been initiated. All containers and nymspaces will be stopped now",
"gitok": "Folder is ready",
"section.SdbuController": "Automation",
"com.up": "Launch compose",
"com.sdbu": "Stop, download from git, rebuild, and start. Full update cycle",
"git.downloaded": "Repository downloaded and updated",
"http.start": "Started Http server for gits webhooks and connecting the client side. Address: ",
"com.build": "Compose build",
"section.ComboController": "NS management",
"get.from": "Downloading the new branch version from the repository for ",
"procces.null": "Process not found for ",
"process.end": "Process has ended",
"com.upall": "Launch all composes",
"com.download": "Download the latest branch version and save it to /ns-files",
"process": "Process: ",
"com.stopall": "Stop all ns",
"up.build": "Building namespace ",
"helpcom": "Command help:",
"up.all": "Launching namespace ",
"section.GitCmd": "GitHub and downloading repositories",
"com.stop": "Stop ns",
"com.ns": "Show all namespaces",
"com.help": "Help",
"app.stopping": "A safe stop of the application has been initiated. All containers and ns will be stopped now",
"com.listx": "Download the latest version of the branch and upload it to /ns-files",
"gitok": "Folder is ready",
"com.gitupd": "Download the latest version of the branch and upload it to /ns-files",
"com.build": "Compose build",
"com.upall": "Launch all composes",
"com.pods": "Show pod status"
}
11 changes: 8 additions & 3 deletions src/main/java/org/example/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ public void run() {
public static void onDisable() {
if (isDisbled) return;
isDisbled = true;
// ComboController.StopAll();

ComboController.StopAll();
System.out.println("Disabled.");
}

Expand Down Expand Up @@ -109,9 +108,15 @@ public static void run() {
Scanner scanner = new Scanner(System.in);

while (true) {
String command = scanner.nextLine();

String command = scanner.nextLine();
if(isDisbled){
System.out.println("CTRL+C to exit");
continue;
}
commandListener(command);


}

}
Expand Down
46 changes: 26 additions & 20 deletions src/main/java/org/example/core/Fastcommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public class Fastcommand {

public boolean onlyOp = true;
private final String rootCommand;
private final String section;
public List<CommandElemet> commands = new ArrayList<>();


Expand All @@ -28,14 +28,14 @@ public String[] argToList(String arg){

public Fastcommand(String rootCommand) {

this.rootCommand = rootCommand;

this.section = rootCommand;

/*
CommandElemet com = new CommandElemet();
com.subcommond = "help";
com.descrip = "Help";
com.event = this::sendHelpCommand;
commands.add(com);
commands.add(com);*/
}

public static class CommandElemet {
Expand All @@ -48,18 +48,27 @@ public static class CommandElemet {

public void sendMessage(String msg) {

System.out.println(ChatColor.BLUE + "[" + rootCommand + "] " + ChatColor.WHITE + msg);
System.out.println( ChatColor.WHITE + msg);

}

public void sendHelpCommand(String[] args) {
String text = Lang.t("helpcom","Хелп по командам:");
String text = "\n"+ ChatColor.RESET+ Lang.t("section."+getClass().getSimpleName(),section) +ChatColor.RESET;
for (CommandElemet com : commands) {
text += "\n" + "/" + rootCommand + " " + com.subcommond;
String line ="";

line += "" + " " + ChatColor.GREEN+ com.subcommond;
for (String arg : com.arguments) {
text += " <" + arg + ">";
line += " <" + arg + ">";
}
text += ChatColor.YELLOW+ " " + Lang.t("com."+com.subcommond, com.descrip);

int margitn = 22;
for(int i= line.length();i<margitn;i++){
line += " ";
}
line += ChatColor.WHITE+ " " + Lang.t("com."+com.subcommond, com.descrip);

text += "\n" + line;
}
sendMessage(text);

Expand All @@ -77,23 +86,17 @@ public boolean input(String rawCommand) {



if (!_root.equals(rootCommand)) return false;

String[] args = new String[Math.max(0, exploded.length - 1)];

String subcomand = "";
if (exploded.length > 1) subcomand = exploded[1];


String[] args = new String[Math.max(0, exploded.length - 2)];


if(exploded.length - 2>0){
for (int i = 2; i < exploded.length; i++) {
args[i-2] = exploded[i ];
if(exploded.length - 1>0){
for (int i = 1; i < exploded.length; i++) {
args[i-1] = exploded[i ];
}
}

return onCommand(subcomand, args);
return onCommand(_root, args);


}
Expand All @@ -110,6 +113,9 @@ public boolean onCommand(String subcommand, String[] args) {
if (!com.subcommond.equalsIgnoreCase(subcommand)) continue;


// System.out.println(subcommand+" / " + com.arguments.size() + " == " + args.length);


if (com.arguments.size() != args.length ) continue;


Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/example/helpers/IpAttempts.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public class IpAttempts {
private static Map<String, Integer> attemptsMap = new HashMap<>();

private static int attemptsMax = 3;
private static int attemptsMax = 17;

public static boolean canTryFromIp(String ip) {
if (!attemptsMap.containsKey(ip)) {
Expand Down
19 changes: 11 additions & 8 deletions src/main/java/org/example/helpers/LogoDesignHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ public class LogoDesignHelper {

public static void logo() {

System.out.println(ChatColor.YELLOW + "==============================");
System.out.println(ChatColor.YELLOW + "| |");
System.out.println(ChatColor.YELLOW + "| DockSabbath |");
System.out.println(ChatColor.YELLOW + "| |");
System.out.println(ChatColor.YELLOW + "==============================\n");
System.out.println(ChatColor.YELLOW + " ==============================");
System.out.println(ChatColor.YELLOW + " | |");
System.out.println(ChatColor.YELLOW + " | DockSabbath |");
System.out.println(ChatColor.YELLOW + " | |");
System.out.println(ChatColor.YELLOW + " ============================== ");

System.out.println("░█▀▄░█▀█░█▀▀░█░█░█▀▀░█▀█░█▀▄░█▀▄░█▀█░▀█▀░█░█\n" +
"░█░█░█░█░█░░░█▀▄░▀▀█░█▀█░█▀▄░█▀▄░█▀█░░█░░█▀█\n" +
"░▀▀░░▀▀▀░▀▀▀░▀░▀░▀▀▀░▀░▀░▀▀░░▀▀░░▀░▀░░▀░░▀░▀");
System.out.println(
" ___ __ ____ __ __ __ __ \n" +
" / _ \\___ ____/ /__ / __/__ _/ / / / ___ _/ /_/ / \n" +
" / // / _ \\/ __/ '_/_\\ \\/ _ `/ _ \\/ _ \\/ _ `/ __/ _ \\\n" +
"/____/\\___/\\__/_/\\_\\/___/\\_,_/_.__/_.__/\\_,_/\\__/_//_/\n" +
" ");

System.out.println(ChatColor.YELLOW + "VERSION: "+version+"\n");
}
Expand Down
21 changes: 19 additions & 2 deletions src/main/java/org/example/services/Combo/ComboController.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static ComboController getInstance() {
}

public ComboController() {
super("combo");
super("Управление неймспейсами");

instance = this;

Expand All @@ -43,6 +43,19 @@ public ComboController() {
com.arguments.add("ns");
commands.add(com);

com = new CommandElemet();
com.subcommond = "stop";
com.descrip = "Остановить ns";
com.event = this::Stop;
com.arguments.add("ns");
commands.add(com);

com = new CommandElemet();
com.subcommond = "stopall";
com.descrip = "Остановить все ns";
com.event = this::StopAllCommand;
commands.add(com);

com = new CommandElemet();
com.subcommond = "upall";
com.descrip = "Запустить все композы";
Expand All @@ -52,13 +65,17 @@ public ComboController() {

com = new CommandElemet();
com.subcommond = "build";
com.descrip = "Билдить композ";
com.descrip = "Билдить коhмпоз";
com.event = this::Build;
com.arguments.add("ns");
commands.add(com);

}

private void StopAllCommand(String[] strings) {
StopAll();
}

public static void ShowAllNs() {
List<NsInfoContract> nsInfos = NsAttachRepository.attacingAllData();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private String ActionRoute(HttpExchange httpExchange) {
return new Gson().toJson(responseContract.error("Client api disabled edit config.json in server"));
}

if (!HashingApi.verify(body.hash, body.data, mainConfig.githubWebhookToken)) {
if (!HashingApi.verify(body.hash, body.data, mainConfig.clientApiToken)) {
return new Gson().toJson(responseContract.error("hash is not correct"));
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/example/services/git/GitCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static GitCmd getInstance() {


public GitCmd() {
super("git");
super("Гитхаб и загрузка репозиториев");


instance = this;
Expand All @@ -24,7 +24,7 @@ public GitCmd() {
CommandElemet com;

com = new CommandElemet();
com.subcommond = "download";
com.subcommond = "gitupd";
com.descrip = "Скачать последнию версию ветки и загрузить в /ns-files";
com.event = this::Download;
com.arguments.add("ns");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class SdbuController extends Fastcommand {


public SdbuController() {
super("combo");
super("Автоматизация");

instance = this;

Expand Down

0 comments on commit fe890ab

Please sign in to comment.