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

Update Command Line Options to use arg_name, not arg_type #1032

Merged
merged 3 commits into from
Nov 22, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
String long_form() default NO_VALUE;

/**
* Set the argument type description.
* Set the argument name.
*/
String arg_type() default NO_VALUE;
String arg_name() default NO_VALUE;
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ private void showUsage() {
public void showUsage(String message) {
ifNotNullThen(message, m -> System.err.println(m));
System.err.println("Options supported:");
optionMap.forEach((option, method) -> System.err.printf(" %s %1s %s%n",
option.short_form(), option.arg_type(), option.description()));
optionMap.forEach((option, method) -> System.err.printf(" %s %12s %s%n",
option.short_form(), option.arg_name(), option.description()));
System.exit(message == null ? LINUX_SUCCESS_CODE : LINUX_ERROR_CODE);
}

Expand Down Expand Up @@ -131,7 +131,7 @@ private boolean processArgEntry(String arg, CommandLineOption option, Method met
if (method.equals(showHelpMethod)) {
showUsage();
} else if (requiresArg(method)) {
checkState(!option.arg_type().isBlank(), "Option with argument missing type parameter");
checkState(!option.arg_name().isBlank(), "Option with argument missing name parameter");
String parameter = argList.remove(0);
method.invoke(target, parameter);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ private void setBlockUnknown() {
blockUnknown = true;
}

@CommandLineOption(short_form = "-c", arg_type = "n", description = "Create registries")
@CommandLineOption(short_form = "-c", arg_name = "count", description = "Create registries")
private void setCreateRegistries(String registrySpec) {
try {
createRegistries = Integer.parseInt(registrySpec);
Expand All @@ -242,7 +242,7 @@ private void setCreateRegistries(String registrySpec) {
}
}

@CommandLineOption(short_form = "-n", arg_type = "n",
@CommandLineOption(short_form = "-n", arg_name = "threads",
description = "Set number of runner threads")
private void setRunnerThreads(String argValue) {
runnerThreads = Integer.parseInt(argValue);
Expand All @@ -262,7 +262,7 @@ private void setExpungeDevices() {
this.updateCloudIoT = true;
}

@CommandLineOption(short_form = "-e", arg_type = "s", description = "Set registry suffix")
@CommandLineOption(short_form = "-e", arg_name = "suffix", description = "Set registry suffix")
private void setRegistrySuffix(String suffix) {
siteModel.getExecutionConfiguration().registry_suffix = suffix;
}
Expand Down Expand Up @@ -348,7 +348,7 @@ private void setMetadataModelOut() {
metadataModelOut = true;
}

@CommandLineOption(short_form = "-l", arg_type = "t", description = "Set idle limit")
@CommandLineOption(short_form = "-l", arg_name = "timeout", description = "Set idle limit")
private void setIdleLimit(String option) {
idleLimit = Duration.parse("PT" + option);
System.err.println("Limiting devices to duration " + idleLimit.toSeconds() + "s");
Expand All @@ -364,7 +364,7 @@ private void setDeviceList(List<String> deviceList) {
blockUnknown = false;
}

@CommandLineOption(short_form = "-f", arg_type = "s", description = "Set PubSub feed topic")
@CommandLineOption(short_form = "-f", arg_name = "topic", description = "Set PubSub feed topic")
private void setFeedTopic(String feedTopic) {
System.err.println("Sending device feed to topic " + feedTopic);
feedPusher = new PubSubPusher(projectId, feedTopic);
Expand Down Expand Up @@ -433,7 +433,7 @@ private SetupUdmiConfig getCloudVersionInfo() {
return ifNotNullGet(cloudIotManager, CloudIotManager::getVersionInformation);
}

@CommandLineOption(short_form = "-s", arg_type = "s", description = "Set site path")
@CommandLineOption(short_form = "-s", arg_name = "site_path", description = "Set site path")
private void setSitePath(String sitePath) {
checkNotNull(SCHEMA_NAME, "schemaName not set yet");
siteDir = new File(sitePath);
Expand Down Expand Up @@ -1178,7 +1178,7 @@ private void initializeDevices(Map<String, LocalDevice> localDevices) {
});
}

@CommandLineOption(short_form = "-p", arg_type = "s", description = "Set project id")
@CommandLineOption(short_form = "-p", arg_name = "project_id", description = "Set project id")
private void setProjectId(String projectId) {
if (NO_SITE.equals(projectId) || projectId == null) {
this.projectId = null;
Expand All @@ -1190,7 +1190,7 @@ private void setProjectId(String projectId) {
this.projectId = projectId;
}

@CommandLineOption(short_form = "-r", arg_type = "s", description = "Set tool root")
@CommandLineOption(short_form = "-r", arg_name = "root_path", description = "Set tool root")
private void setToolRoot(String toolRoot) {
try {
schemaBase = new File(toolRoot, SCHEMA_BASE_PATH);
Expand Down Expand Up @@ -1271,7 +1271,8 @@ public List<Object> getMockActions() {
return cloudIotManager.getMockActions();
}

@CommandLineOption(short_form = "-a", arg_type = "s", description = "Set alternate registry")
@CommandLineOption(short_form = "-a", arg_name = "alternate",
description = "Set alternate registry")
private void setTargetRegistry(String altRegistry) {
siteModel.getExecutionConfiguration().registry_id = altRegistry;
siteModel.getExecutionConfiguration().alt_registry = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ private void setProfileMode() {
MqttPublisher.reportStatistics = true;
}

@CommandLineOption(short_form = "-d", arg_type = "n", description = "Report delay (sec)")
@CommandLineOption(short_form = "-d", arg_name = "delay", description = "Report delay (sec)")
private void setReportDelay(String arg) {
reportingDelaySec = Integer.parseInt(arg);
}
Expand All @@ -388,7 +388,7 @@ private void setValidateCurrent() {
validateCurrent = true;
}

@CommandLineOption(short_form = "-p", arg_type = "s", description = "Set project id")
@CommandLineOption(short_form = "-p", arg_name = "project_id", description = "Set project id")
private void setProjectId(String projectId) {
if (!projectId.startsWith(PROJECT_PROVIDER_PREFIX)) {
config.project_id = projectId;
Expand All @@ -399,7 +399,8 @@ private void setProjectId(String projectId) {
config.project_id = parts[1];
}

@CommandLineOption(short_form = "-t", arg_type = "s", description = "Validate pub sub target")
@CommandLineOption(short_form = "-t", arg_name = "target",
description = "Validate pub sub target")
private void validatePubSub(String pubSubCombo) {
validatePubSub(pubSubCombo, true);
}
Expand Down Expand Up @@ -439,7 +440,8 @@ MessageReadingClient getMessageReadingClient() {
return (MessageReadingClient) client;
}

@CommandLineOption(short_form = "-r", arg_type = "s", description = "Validate message trace")
@CommandLineOption(short_form = "-r", arg_name = "message_dir",
description = "Validate message trace")
private void validateMessageTrace(String messageDir) {
client = new MessageReadingClient(getRegistryId(), messageDir);
dataSinks.add(client);
Expand All @@ -456,7 +458,7 @@ Validator prepForMock() {
*
* @param siteDir site model directory
*/
@CommandLineOption(short_form = "-s", arg_type = "s", description = "Set site directory")
@CommandLineOption(short_form = "-s", arg_name = "site_dir", description = "Set site directory")
private void setSiteDir(String siteDir) {
config.site_model = siteDir;
final File baseDir;
Expand All @@ -482,7 +484,7 @@ private ExecutionConfiguration resolveSiteConfig(ExecutionConfiguration config,
return GeneralUtils.mergeObject(siteConfig, config);
}

@CommandLineOption(short_form = "-w", arg_type = "s", description = "Write trace output")
@CommandLineOption(short_form = "-w", arg_name = "trace_dir", description = "Write trace output")
private void setMessageTraceDir(String writeDirArg) {
traceDir = new File(writeDirArg);
outputLogger.info("Tracing message capture to " + traceDir.getAbsolutePath());
Expand Down Expand Up @@ -525,7 +527,7 @@ private ReportingDevice newReportingDevice(String device) {
*
* @param schemaPath schema specification directory
*/
@CommandLineOption(short_form = "-a", arg_type = "s", description = "Set schema path")
@CommandLineOption(short_form = "-a", arg_name = "schema_path", description = "Set schema path")
private void setSchemaSpec(String schemaPath) {
File schemaPart = new File(schemaPath);
boolean rawPath = schemaPart.isAbsolute() || Strings.isNullOrEmpty(config.udmi_root);
Expand Down Expand Up @@ -1179,7 +1181,8 @@ private void validateFiles(String schemaSpec, String prefix, String targetSpec)
schemaExceptions.throwIfNotEmpty();
}

@CommandLineOption(short_form = "-f", arg_type = "s", description = "Validate from files")
@CommandLineOption(short_form = "-f", arg_name = "target_spec",
description = "Validate from files")
private void validateFilesOutput(String targetSpec) {
try {
String[] parts = targetSpec.split(":");
Expand Down