Skip to content

Commit

Permalink
move command classes to enable usage of config path
Browse files Browse the repository at this point in the history
  • Loading branch information
rakow committed Feb 10, 2024
1 parent 2fce962 commit c658cae
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.matsim.api.core.v01.Scenario;
import org.matsim.application.commands.RunScenario;
import org.matsim.application.commands.ShowGUI;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigGroup;
import org.matsim.core.config.ConfigUtils;
Expand Down Expand Up @@ -211,6 +209,15 @@ public Integer call() throws Exception {
return 0;
}

File getConfigPath() {
return configPath;
}

@Nullable
String getDefaultScenario() {
return defaultScenario;
}

/**
* Custom module configs that will be added to the {@link Config} object.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package org.matsim.application.commands;
package org.matsim.application;

import org.matsim.application.MATSimApplication;
import picocli.CommandLine;

import java.util.concurrent.Callable;

@CommandLine.Command(name = "run", description = "Run the scenario")
public class RunScenario implements Callable<Integer> {
class RunScenario implements Callable<Integer> {

@CommandLine.ParentCommand
private MATSimApplication app;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package org.matsim.application.commands;
package org.matsim.application;

import org.matsim.application.MATSimApplication;
import org.matsim.run.gui.Gui;
import picocli.CommandLine;

import java.io.File;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;

@CommandLine.Command(name = "gui", description = "Run the scenario through the MATSim GUI")
public class ShowGUI implements Callable<Integer> {
class ShowGUI implements Callable<Integer> {

@CommandLine.ParentCommand
private MATSimApplication parent;
Expand All @@ -26,7 +26,15 @@ public Integer call() throws Exception {
name = name.substring(MATSimApplication.COLOR.length(), name.length() - 4);
}

Future<Gui> f = Gui.show(name, parent.getClass());
File configFile = null;

// Try to load default config file
if (parent.getConfigPath() != null && parent.getConfigPath().exists())
configFile = parent.getConfigPath();
else if (parent.getDefaultScenario() != null && new File(parent.getDefaultScenario()).exists())
configFile = new File(parent.getDefaultScenario());

Future<Gui> f = Gui.show(name, parent.getClass(), configFile);

Gui gui = f.get();

Expand Down

0 comments on commit c658cae

Please sign in to comment.