Skip to content

Commit

Permalink
Update registrar usage forms in its help function & update docs
Browse files Browse the repository at this point in the history
khyatimahendru committed Dec 27, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent b00264d commit e05d414
Showing 3 changed files with 37 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -28,6 +28,7 @@ public class CommandLineProcessor {
private static final int LINUX_ERROR_CODE = -1;
private final Object target;
private final Method showHelpMethod;
private List<String> usageForms = null;

Map<CommandLineOption, Method> optionMap = new TreeMap<>(
(a, b) -> CASE_INSENSITIVE_ORDER.compare(getSortArg(a), getSortArg(b)));
@@ -69,6 +70,13 @@ public CommandLineProcessor(Object target) {
checkState(duplicateLong.isEmpty(), "duplicate short form command line option");
}

public CommandLineProcessor(Object target, List<String> usageForms) {
this(target);
if (usageForms != null && !usageForms.isEmpty()) {
this.usageForms = usageForms;
}
}

private Method getShowHelpMethod() {
try {
return CommandLineProcessor.class.getDeclaredMethod("showUsage");
@@ -91,6 +99,10 @@ private void showUsage() {
*/
public void showUsage(String message) {
ifNotNullThen(message, m -> System.err.println(m));
ifNotNullThen(this.usageForms, () -> {
System.err.println("Usage forms:");
this.usageForms.forEach(form -> System.err.printf("\t%s%n", form));
});
System.err.println("Options supported:");
optionMap.forEach((option, method) -> System.err.printf(" %s %12s %s%n",
option.short_form(), option.arg_name(), option.description()));
27 changes: 19 additions & 8 deletions docs/tools/registrar.md
Original file line number Diff line number Diff line change
@@ -39,22 +39,33 @@ be used to specific specific device(s) to register (rather than all).
```
Usage:
bin/registrar site_path [project_id] [options] [devices...]
bin/registrar site_model project_spec [options] [devices...]
bin/registrar config_file
bin/registrar site_spec [options] [devices...]
```

* `config_file`: Path to a configuration file which contains configuration options;
* `site_path`: The _directory_ containing the site model, or a model-with-project _file_ directly.
* `project_id`: The project ID that contains the target registry. The project ID can be prepended with iot_provider:
* `site_model`: The path to the _directory_ containing the site model, or a model-with-project _file_ directly.
* `project_spec`: The project ID that contains the target registry. The project ID can be prepended with iot_provider:
* `//clearblade/PROJECT_ID` for a public ClearBlade project.
* `//gbos/PROJECT_ID` for a Google operated ClearBlade project.
* `site_spec`: Path to a configuration file which contains configuration options;
* `options`: Various options to impact behavior:
* `-u` Update.
* `-d` Delete all device in the site model from the registry (combine with `-x` to delete all devices from the registry)
* `-a` Set alternate registry
* `-b` Block unknown devices.
* `-x` Delete unknown devices from the registry.
* `-c` Count of registries to be created
* `-d` Delete all device in the site model from the registry (combine with `-x` to delete all devices from the registry)
* `-e` Set registry suffix
* `-f` Set PubSub feed topic
* `-h` Show help and exit
* `-l` Set idle limit
* `-m` Initial metadata model out
* `-n` Number of thread counts.
* `-p` Set Project ID
* `-q` Query only, registry to not be updated
* `-r` Set tool root path
* `-s` Set site path
* `-t` Do not validate metadata
* `-x` Delete unknown devices from the registry.
* `devices`: Multiple device entries for limited registration. Can be just the device name
(`AHU-12`), or path to device (`site/devices/AHU-12`) for use with file-name glob.

Original file line number Diff line number Diff line change
@@ -42,6 +42,7 @@
import com.github.fge.jsonschema.main.JsonSchema;
import com.github.fge.jsonschema.main.JsonSchemaFactory;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
@@ -127,7 +128,11 @@ public class Registrar {
private final Map<String, JsonSchema> schemas = new HashMap<>();
private final String generation = getGenerationString();
private final Set<Summarizer> summarizers = new HashSet<>();
private final CommandLineProcessor commandLineProcessor = new CommandLineProcessor(this);
private final List<String> usageForms = ImmutableList.of(
"bin/registrar site_model project_spec [options] [devices...]",
"bin/registrar site_spec [options] [devices...]");
private final CommandLineProcessor commandLineProcessor = new CommandLineProcessor(this,
usageForms);
private CloudIotManager cloudIotManager;
private File schemaBase;
private PubSubPusher updatePusher;

0 comments on commit e05d414

Please sign in to comment.