Skip to content

Commit

Permalink
Make --dir param optional for upgradetool (#3591)
Browse files Browse the repository at this point in the history
* Make --dir param optional for upgradetool

Almost all openHAB installations should have the $OPENHAB_USERDATA env variable set.
If this is the case, the user does not have to provide a directory, so this parameter can be made optional.

Signed-off-by: Kai Kreuzer <kai@openhab.org>
  • Loading branch information
kaikreuzer authored May 4, 2023
1 parent c846487 commit 9c59071
Showing 1 changed file with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ public class UpgradeTool {
private static Options getOptions() {
Options options = new Options();

options.addOption(
Option.builder().longOpt(OPT_DIR).desc("directory to process").numberOfArgs(1).required().build());
options.addOption(Option.builder().longOpt(OPT_DIR).desc("directory to process").numberOfArgs(1).build());
options.addOption(Option.builder().longOpt(OPT_COMMAND).numberOfArgs(1).desc("command to execute").build());
options.addOption(Option.builder().longOpt(OPT_LOG).numberOfArgs(1).desc("log verbosity").build());
options.addOption(Option.builder().longOpt(OPT_FORCE).desc("force execution (even if already done)").build());
Expand All @@ -64,14 +63,21 @@ public static void main(String[] args) {

System.setProperty(org.slf4j.impl.SimpleLogger.DEFAULT_LOG_LEVEL_KEY, loglevel);

String baseDir = commandLine.hasOption(OPT_DIR) ? commandLine.getOptionValue(OPT_DIR) : "";
boolean force = commandLine.hasOption(OPT_FORCE) ? true : false;
String baseDir = commandLine.hasOption(OPT_DIR) ? commandLine.getOptionValue(OPT_DIR)
: System.getenv("OPENHAB_USERDATA");
if (baseDir == null || baseDir.isBlank()) {
System.out.println(
"Please either set the environment variable ${OPENHAB_USERDATA} or provide a directory through the --dir option.");
System.exit(0);
} else {
boolean force = commandLine.hasOption(OPT_FORCE) ? true : false;

Upgrader upgrader = new Upgrader(baseDir, force);
if (commandLine.hasOption(ITEM_COPY_UNIT_TO_METADATA)) {
upgrader.itemCopyUnitToMetadata();
} else if (commandLine.hasOption(LINK_UPGRADE_JS_PROFILE)) {
upgrader.linkUpgradeJsProfile();
Upgrader upgrader = new Upgrader(baseDir, force);
if (commandLine.hasOption(ITEM_COPY_UNIT_TO_METADATA)) {
upgrader.itemCopyUnitToMetadata();
} else if (commandLine.hasOption(LINK_UPGRADE_JS_PROFILE)) {
upgrader.linkUpgradeJsProfile();
}
}
} catch (ParseException e) {
HelpFormatter formatter = new HelpFormatter();
Expand Down

0 comments on commit 9c59071

Please sign in to comment.