From 2c84a2478e7359dde2e6830b5bde12535efa0514 Mon Sep 17 00:00:00 2001 From: Mark Nellemann Date: Tue, 29 Mar 2022 13:31:43 +0200 Subject: [PATCH] Support Windows default location for config file. --- CHANGELOG.md | 8 ++++- build.gradle | 2 +- gradle.properties | 2 +- .../java/biz/nellemann/hmci/Application.java | 7 ++-- .../biz/nellemann/hmci/DefaultProvider.java | 33 +++++++++++++++++++ 5 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 src/main/java/biz/nellemann/hmci/DefaultProvider.java diff --git a/CHANGELOG.md b/CHANGELOG.md index ad99a88..484e7e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,12 @@ All notable changes to this project will be documented in this file. -## [1.3.0] - 2022-02-xx +## [1.3.1] - 2022-04-xx +### Added +- Default configuration location on Windows platform. + + +## [1.3.0] - 2022-02-04 ### Changed - Correct use of InfluxDB batch writing. @@ -16,6 +21,7 @@ All notable changes to this project will be documented in this file. ### Added - Options to include/exclude Managed Systems and/or Logical Partitions. +[1.3.1]: https://bitbucket.org/mnellemann/hmci/branches/compare/v1.3.1%0Dv1.3.0 [1.3.0]: https://bitbucket.org/mnellemann/hmci/branches/compare/v1.3.0%0Dv1.2.8 [1.2.8]: https://bitbucket.org/mnellemann/hmci/branches/compare/v1.2.8%0Dv1.2.7 [1.2.7]: https://bitbucket.org/mnellemann/hmci/branches/compare/v1.2.7%0Dv1.2.6 diff --git a/build.gradle b/build.gradle index 88e3762..dda3d57 100644 --- a/build.gradle +++ b/build.gradle @@ -22,7 +22,7 @@ sourceCompatibility = projectJavaVersion targetCompatibility = projectJavaVersion dependencies { - annotationProcessor 'info.picocli:picocli-codegen:4.6.2' + annotationProcessor 'info.picocli:picocli-codegen:4.6.3' implementation 'info.picocli:picocli:4.6.3' implementation 'org.jsoup:jsoup:1.14.3' implementation 'com.squareup.okhttp3:okhttp:4.9.3' diff --git a/gradle.properties b/gradle.properties index 97f323d..96a53af 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ projectId = hmci projectGroup = biz.nellemann.hmci -projectVersion = 1.3.0 +projectVersion = 1.3.1 projectJavaVersion = 1.8 diff --git a/src/main/java/biz/nellemann/hmci/Application.java b/src/main/java/biz/nellemann/hmci/Application.java index aa02695..d1d2800 100644 --- a/src/main/java/biz/nellemann/hmci/Application.java +++ b/src/main/java/biz/nellemann/hmci/Application.java @@ -28,13 +28,14 @@ import java.util.concurrent.Callable; @Command(name = "hmci", mixinStandardHelpOptions = true, - versionProvider = biz.nellemann.hmci.VersionProvider.class) + versionProvider = biz.nellemann.hmci.VersionProvider.class, + defaultValueProvider = biz.nellemann.hmci.DefaultProvider.class) public class Application implements Callable { - @Option(names = { "-c", "--conf" }, description = "Configuration file [default: '/etc/hmci.toml'].", defaultValue = "/etc/hmci.toml", paramLabel = "") + @Option(names = { "-c", "--conf" }, description = "Configuration file [default: ${DEFAULT-VALUE}].", paramLabel = "") private File configurationFile; - @Option(names = { "-d", "--debug" }, description = "Enable debugging [default: 'false'].") + @Option(names = { "-d", "--debug" }, description = "Enable debugging [default: false].") private boolean[] enableDebug = new boolean[0]; diff --git a/src/main/java/biz/nellemann/hmci/DefaultProvider.java b/src/main/java/biz/nellemann/hmci/DefaultProvider.java new file mode 100644 index 0000000..a70aeb6 --- /dev/null +++ b/src/main/java/biz/nellemann/hmci/DefaultProvider.java @@ -0,0 +1,33 @@ +package biz.nellemann.hmci; + +import picocli.CommandLine; + +public class DefaultProvider implements CommandLine.IDefaultValueProvider { + + public String defaultValue(CommandLine.Model.ArgSpec argSpec) throws Exception { + if(argSpec.isOption()) { + switch (argSpec.paramLabel()) { + case "": + return getDefaultConfigFileLocation(); + default: + return null; + } + } + return null; + } + + private boolean isWindowsOperatingSystem() { + String os = System.getProperty("os.name"); + return os.toLowerCase().startsWith("windows"); + } + + private String getDefaultConfigFileLocation() { + String configFilePath; + if(isWindowsOperatingSystem()) { + configFilePath = System.getProperty("user.home") + "\\hmci.toml"; + } else { + configFilePath = "/etc/hmci.toml"; + } + return configFilePath; + } +}