Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add v3 argument #12

Merged
merged 1 commit into from
Aug 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@ directory. Alternatively you can adjust the program arguments to specify the fil

When enabling both features, the converting feature will run first, so the appending feature can then use the generated
.items file to append the channel links.

With the `-3`/`--v3`/`--openhab3` parameters default values used since openHAB version 3.X are set. Additional
parameters that specify a custom file always have priority over these defaults.
19 changes: 17 additions & 2 deletions src/main/java/voruti/json2config/Starter.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;
import voruti.json2config.service.ChannelAppender;
import voruti.json2config.service.Constants;
import voruti.json2config.service.Converter;
import voruti.json2config.service.Type;

Expand All @@ -22,14 +23,18 @@ public class Starter implements Runnable {
description = "enable the appending feature")
private boolean doChannelLinks;

@Option(names = {"-3", "--openhab3", "--v3", "--openhab-v3", "--openhabv3", "--openhab-3"},
description = "set default file names used since openHAB version 3.X")
private boolean defaultV3;


@Option(names = {"-i", "--in", "--json"},
defaultValue = "org.eclipse.smarthome.core.items.Item.json",
defaultValue = Constants.DEFAULT_V2_JSON_FILE,
description = "specify the input .json file")
private String jsonFile;

@Option(names = {"--channel-file", "--channel-link-file"},
defaultValue = "org.eclipse.smarthome.core.thing.link.ItemChannelLink.json",
defaultValue = Constants.DEFAULT_V2_CHANNEL_FILE,
description = "specify the .json file location containing the channel links")
private String channelFile;

Expand All @@ -54,6 +59,16 @@ public static void main(String[] args) {
*/
@Override
public void run() {
// openHAB 3.X defaults:
if (defaultV3) {
if (jsonFile.equals(Constants.DEFAULT_V2_JSON_FILE)) {
jsonFile = Constants.DEFAULT_V3_JSON_FILE;
}
if (channelFile.equals(Constants.DEFAULT_V2_CHANNEL_FILE)) {
channelFile = Constants.DEFAULT_V3_CHANNEL_FILE;
}
}

// start Converter:
if (!noConverter) {
Converter.start(jsonFile, outFile, Type.ITEM);
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/voruti/json2config/service/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@

public final class Constants {

// logging constants:
public static final String LOG_CANT_OPEN_FILE = "Can't open file {}";

// default voruti.json2config.Starter argument values:
public static final String DEFAULT_V2_JSON_FILE = "org.eclipse.smarthome.core.items.Item.json";
public static final String DEFAULT_V3_JSON_FILE = "org.openhab.core.items.Item.json";
public static final String DEFAULT_V2_CHANNEL_FILE = "org.eclipse.smarthome.core.thing.link.ItemChannelLink.json";
public static final String DEFAULT_V3_CHANNEL_FILE = "org.openhab.core.thing.link.ItemChannelLink.json";


private Constants() {
}
Expand Down