Skip to content

Commit

Permalink
ISPN-14040 CLI config reset
Browse files Browse the repository at this point in the history
  • Loading branch information
tristantarrant authored and pruivo committed Aug 1, 2022
1 parent 663ffa8 commit 3288611
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
2 changes: 2 additions & 0 deletions cli/src/main/java/org/infinispan/cli/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public interface Context extends AeshContext {

Properties getProperties();

void resetProperties();

void saveProperties();

void setSslContext(SSLContextSettings sslContext);
Expand Down
21 changes: 20 additions & 1 deletion cli/src/main/java/org/infinispan/cli/commands/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
* @since 11.0
**/
@MetaInfServices(Command.class)
@GroupCommandDefinition(name = "config", description = "Configuration operations", groupCommands = {Config.Set.class, Config.Get.class, Config.Convert.class})
@GroupCommandDefinition(name = "config", description = "Configuration operations", groupCommands = {Config.Set.class, Config.Get.class, Config.Reset.class, Config.Convert.class})
public class Config extends CliCommand {

@Option(shortName = 'h', hasValue = false, overrideRequired = true)
Expand Down Expand Up @@ -113,6 +113,25 @@ public CommandResult exec(ContextAwareCommandInvocation invocation) {
}
}

@CommandDefinition(name = "reset", description = "Resets all configuration properties to their default values")
public static class Reset extends CliCommand {
@Option(shortName = 'h', hasValue = false, overrideRequired = true)
protected boolean help;

@Override
public boolean isHelp() {
return help;
}

@Override
public CommandResult exec(ContextAwareCommandInvocation invocation) {
Context context = invocation.getContext();
context.resetProperties();
context.saveProperties();
return CommandResult.SUCCESS;
}
}

@CommandDefinition(name = "convert", description = "Converts configuration to different formats.", activator = ConfigConversionAvailable.class)
public static class Convert extends CliCommand {

Expand Down
5 changes: 5 additions & 0 deletions cli/src/main/java/org/infinispan/cli/impl/ContextImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ public Properties getProperties() {
return properties;
}

@Override
public void resetProperties() {
properties.clear();
}

@Override
public void saveProperties() {
Path configFile = configPath.resolve(CONFIG_FILE);
Expand Down
3 changes: 3 additions & 0 deletions cli/src/main/resources/help/config.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ Sets the value of a specific property. If you do not specify a value, the proper
*config get* 'name'::
Retrieves the value of a specific property.

*config reset*::
Resets all properties to their default values.

*config convert* --format=[xml|json|yaml] [-o outputFile] [inputFile]::
Converts a configuration file to a different format.

Expand Down

0 comments on commit 3288611

Please sign in to comment.