Skip to content

Commit

Permalink
GH-77 Support contextless commands through the program arguments (Res…
Browse files Browse the repository at this point in the history
…olve #57)
  • Loading branch information
dzikoysk committed May 27, 2020
1 parent ac1cab6 commit 0f2e6b7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
14 changes: 9 additions & 5 deletions src/main/java/org/panda_lang/reposilite/Reposilite.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,16 @@ public final class Reposilite {

public static void main(String[] args) throws Exception {
Reposilite reposilite = new Reposilite();
reposilite.launch();
reposilite.launch(args);
}

public void launch() throws Exception {
public void launch(String[] args) throws Exception {
this.console = new Console(this);

if (console.executeArguments(args)) {
return;
}

getLogger().info("");
getLogger().info(ansi().bold().fg(Color.GREEN).a("Reposilite ").reset().a(ReposiliteConstants.VERSION).reset().toString());
getLogger().info("");
Expand All @@ -64,11 +70,9 @@ public void launch() throws Exception {
ConfigurationLoader configurationLoader = new ConfigurationLoader();
this.configuration = configurationLoader.load();

this.console = new Console(this);
console.hook();

Thread shutdownHook = new Thread(() -> Try.run(this::shutdown).orElseRun(Throwable::printStackTrace));
Runtime.getRuntime().addShutdownHook(shutdownHook);
console.hook();

FrontendLoader frontendLoader = new FrontendLoader();
this.frontend = frontendLoader.loadFrontend(ReposiliteConstants.FRONTEND_FILE_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

public final class ReposiliteConstants {

public static final String VERSION = "2.4.2";
public static final String VERSION = "2.4.3";

public static final String REMOTE_VERSION = "https://repo.panda-lang.org/org/panda-lang/reposilite/latest";

Expand Down
26 changes: 26 additions & 0 deletions src/main/java/org/panda_lang/reposilite/console/Console.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@

import io.vavr.control.Try;
import org.panda_lang.reposilite.Reposilite;
import org.panda_lang.reposilite.ReposiliteConstants;
import org.panda_lang.reposilite.auth.KeygenCommand;
import org.panda_lang.reposilite.auth.RevokeCommand;
import org.panda_lang.reposilite.auth.TokensListCommand;
import org.panda_lang.reposilite.metadata.PurgeCommand;
import org.panda_lang.reposilite.stats.StatsCommand;
import org.panda_lang.utilities.commons.ArrayUtils;

public class Console {

Expand All @@ -46,6 +48,8 @@ public boolean execute(String command) throws Exception {
switch (command.toLowerCase()) {
case "help":
return displayHelp();
case "version":
return displayVersion();
case "status":
return displayStatus();
case "purge":
Expand Down Expand Up @@ -85,6 +89,28 @@ public boolean execute(String command) throws Exception {
}
}

public boolean executeArguments(String[] arguments) {
if (ArrayUtils.isEmpty(arguments)) {
return false;
}

String command = arguments[0].toLowerCase();

switch (command) {
case "help":
return displayHelp();
case "version":
return displayVersion();
default:
return false;
}
}

public boolean displayVersion() {
Reposilite.getLogger().info("Reposilite " + ReposiliteConstants.VERSION);
return true;
}

public boolean displayHelp() {
return new HelpCommand().call(reposilite);
}
Expand Down

0 comments on commit 0f2e6b7

Please sign in to comment.