Skip to content

Commit

Permalink
Merge branch 'master' into sheet-logger
Browse files Browse the repository at this point in the history
  • Loading branch information
khyatimahendru committed Jan 24, 2025
2 parents 43189e3 + 3c73593 commit 306d7c2
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Map<CommandLineOption, Method> optionMap = new TreeMap<>(
(a, b) -> CASE_INSENSITIVE_ORDER.compare(getSortArg(a), getSortArg(b)));
Expand Down Expand Up @@ -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");
Expand All @@ -91,6 +99,10 @@ private void showUsage() {
*/
public void showUsage(String message) {
ifNotNullThen(message, m -> System.err.println(m));
ifNotNullThen(usageForms, () -> {
System.err.println("Usage forms:");
usageForms.forEach(form -> System.err.printf(" %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()));
Expand Down
27 changes: 19 additions & 8 deletions docs/tools/registrar.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,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.SetView;
Expand Down Expand Up @@ -131,7 +132,11 @@ public class Registrar {
private final Map<String, JsonSchema> schemas = new HashMap<>();
private final String generation = JsonUtil.isoConvert();
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;
Expand Down

0 comments on commit 306d7c2

Please sign in to comment.