Skip to content

Commit

Permalink
Merge pull request #22917 from ebullient/registry-config
Browse files Browse the repository at this point in the history
CLI: fix file handling in registry remove; more feedback
  • Loading branch information
aloubyansky authored Jan 16, 2022
2 parents 0ab5164 + 1827376 commit 9bf530c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import io.quarkus.cli.registry.BaseRegistryCommand;
import io.quarkus.registry.config.RegistriesConfig;
import io.quarkus.registry.config.RegistryConfig;
import picocli.CommandLine;

@CommandLine.Command(name = "add", sortOptions = false, showDefaultValues = true, mixinStandardHelpOptions = false, header = "Add a Quarkus extension registry", description = "%n"
Expand All @@ -30,21 +31,25 @@ public Integer call() throws Exception {
existingConfig = Files.exists(configYaml);
}

registryClient.refreshRegistryCache(output);
final RegistriesConfig.Mutable config;
if (configYaml != null && !existingConfig) {
// we're creating a new configuration for a new file
config = RegistriesConfig.builder();
} else {
config = registryClient.resolveConfig().mutable();
}
registryClient.refreshRegistryCache(output);

boolean persist = false;
for (String registryId : registryIds) {
persist |= config.addRegistry(registryId);
}

if (persist) {
output.printText("Configured registries:");
for (RegistryConfig rc : config.getRegistries()) {
output.printText("- " + rc.getId());
}
if (configYaml != null) {
config.persist(configYaml);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import io.quarkus.cli.registry.BaseRegistryCommand;
import io.quarkus.registry.config.RegistriesConfig;
import io.quarkus.registry.config.RegistryConfig;
import picocli.CommandLine;

@CommandLine.Command(name = "remove", sortOptions = false, showDefaultValues = true, mixinStandardHelpOptions = false, header = "Remove a Quarkus extension registry", description = "%n"
Expand All @@ -31,26 +32,29 @@ public Integer call() throws Exception {
}

final RegistriesConfig.Mutable config;
if (existingConfig) {
registryClient.refreshRegistryCache(output);
config = registryClient.resolveConfig().mutable();
if (config.getSource().getFilePath() == null) {
output.error("Can only modify file-based configuration. Config source is " + config.getSource().describe());
return CommandLine.ExitCode.SOFTWARE;
}
if (configYaml != null && !existingConfig) {
// we're creating a new configuration for a new file
config = RegistriesConfig.builder();
} else {
output.error("Can only remove registries from an existing configuration. The specified config file does not exist: "
+ configYaml);
return CommandLine.ExitCode.SOFTWARE;
config = registryClient.resolveConfig().mutable();
}
registryClient.refreshRegistryCache(output);

boolean persist = false;
for (String registryId : registryIds) {
persist |= config.removeRegistry(registryId);
}

if (persist) {
config.persist();
output.printText("Configured registries:");
for (RegistryConfig rc : config.getRegistries()) {
output.printText("- " + rc.getId());
}
if (configYaml != null) {
config.persist(configYaml);
} else {
config.persist();
}
}
return CommandLine.ExitCode.OK;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import picocli.CommandLine;
import picocli.CommandLine.Help.ColorScheme;
import picocli.CommandLine.Model.CommandSpec;
import picocli.CommandLine.Spec;

public class OutputOptionMixin implements MessageWriter {

Expand Down Expand Up @@ -83,7 +82,7 @@ public boolean isAnsiEnabled() {
return CommandLine.Help.Ansi.AUTO.enabled();
}

public void printText(String[] text) {
public void printText(String... text) {
for (String line : text) {
out().println(colorScheme().ansi().new Text(line, colorScheme()));
}
Expand Down

0 comments on commit 9bf530c

Please sign in to comment.