From edabc867dca41e44b98a368a86fdc460d985465a Mon Sep 17 00:00:00 2001 From: rakow Date: Sat, 10 Feb 2024 18:26:52 +0100 Subject: [PATCH] fix merging of default arguments --- .../matsim/application/ApplicationUtils.java | 4 ++-- .../matsim/application/MATSimApplication.java | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/contribs/application/src/main/java/org/matsim/application/ApplicationUtils.java b/contribs/application/src/main/java/org/matsim/application/ApplicationUtils.java index 07824aee849..9a3099df090 100644 --- a/contribs/application/src/main/java/org/matsim/application/ApplicationUtils.java +++ b/contribs/application/src/main/java/org/matsim/application/ApplicationUtils.java @@ -61,11 +61,11 @@ public static boolean isRunFromDesktop() { // check if gui was explicitly enabled String env = System.getenv().getOrDefault("RUN_GUI", "false"); - if (env.equalsIgnoreCase("true") || env.equals("1") ) + if (env.equalsIgnoreCase("true") || env.equals("1")) return true; String property = System.getProperty("RUN_GUI", "false"); - if (property.equalsIgnoreCase("true") || property.equals("1") ) + if (property.equalsIgnoreCase("true") || property.equals("1")) return true; String macIdentifier = System.getenv().getOrDefault("__CFBundleIdentifier", "none"); diff --git a/contribs/application/src/main/java/org/matsim/application/MATSimApplication.java b/contribs/application/src/main/java/org/matsim/application/MATSimApplication.java index b1820079f48..286f1540b4b 100644 --- a/contribs/application/src/main/java/org/matsim/application/MATSimApplication.java +++ b/contribs/application/src/main/java/org/matsim/application/MATSimApplication.java @@ -395,16 +395,25 @@ public static void runWithDefaults(Class clazz, Str } else { // run if no other command is present if (args.length > 0) { + // valid command is present if (args[0].equals("run") || args[0].equals("prepare") || args[0].equals("analysis") || args[0].equals("gui") ){ - // valid command is present - } else + // If this is a run command, the default args can be applied + if (args[0].equals("run")) + args = ApplicationUtils.mergeArgs(args, defaultArgs); + + } else { // Automatically add run command - args = ApplicationUtils.mergeArgs(new String[]{"run"}, defaultArgs); + String[] runArgs = ApplicationUtils.mergeArgs(new String[]{"run"}, defaultArgs); + args = ApplicationUtils.mergeArgs(defaultArgs, runArgs); + } + } else // Automatically add run command args = ApplicationUtils.mergeArgs(new String[]{"run"}, defaultArgs); - run(clazz, ApplicationUtils.mergeArgs(args, defaultArgs)); + log.info("Running {} with: {}", clazz.getSimpleName(), String.join(" ", args)); + + run(clazz, args); } }