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

CLI: fix file handling in registry remove; more feedback #22917

Merged
merged 1 commit into from
Jan 16, 2022
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 @@ -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