Skip to content

Commit

Permalink
Fix command resets
Browse files Browse the repository at this point in the history
  • Loading branch information
jameskleeh committed May 22, 2019
1 parent e088cc8 commit 1ab5612
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 27 deletions.
17 changes: 7 additions & 10 deletions cli/src/main/groovy/io/micronaut/cli/MicronautCli.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import io.micronaut.cli.profile.ExecutionContext
import io.micronaut.cli.profile.Profile
import io.micronaut.cli.profile.ProfileRepository
import io.micronaut.cli.profile.ProjectContext
import io.micronaut.cli.profile.ResetableCommand
import io.micronaut.cli.profile.commands.ArgumentCompletingCommand
import io.micronaut.cli.profile.commands.CommandRegistry
import io.micronaut.cli.profile.commands.CommonOptionsMixin
Expand Down Expand Up @@ -236,7 +237,9 @@ class MicronautCli {
while (pr.hasSubcommand()) { pr = pr.subcommand() } // most specific subcommand
Command command = pr.commandSpec().userObject() as Command
int result = executeCommand(command, pr) ? 0 : 1
command.reset()
if (command instanceof ResetableCommand) {
command.reset()
}
return result
} else if (parseResult.unmatched()) {
return getBaseUsage()
Expand All @@ -250,7 +253,9 @@ class MicronautCli {
while (pr.hasSubcommand()) { pr = pr.subcommand() } // most specific subcommand
Command command = pr.commandSpec().userObject() as Command
boolean result = executeCommand(command, pr)
command.reset()
if (command instanceof ResetableCommand) {
command.reset()
}
return result
}] as Profile

Expand Down Expand Up @@ -649,10 +654,6 @@ class MicronautCli {
return false
}

@Override
void reset() {

}
}

@Canonical
Expand All @@ -667,10 +668,6 @@ class MicronautCli {
return true
}

@Override
void reset() {

}
}

private static String[] splitCommandLine(String commandLine) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ package io.micronaut.cli.profile
* @author Graeme Rocher
* @since 1.0
*/
interface ProfileCommand extends ResetableCommand {
interface ProfileCommand extends Command {
/**
* @return The profile of the command
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import io.micronaut.cli.profile.OneOfFeatureGroup
import io.micronaut.cli.profile.Profile
import io.micronaut.cli.profile.ProfileRepository
import io.micronaut.cli.profile.ProfileRepositoryAware
import io.micronaut.cli.profile.ResetableCommand
import io.micronaut.cli.util.NameUtils
import io.micronaut.cli.util.VersionInfo
import picocli.CommandLine.Command
Expand All @@ -49,7 +50,7 @@ import java.nio.file.attribute.BasicFileAttributes
*/
@CompileStatic
@Command()
abstract class AbstractCreateCommand extends ArgumentCompletingCommand implements ProfileRepositoryAware {
abstract class AbstractCreateCommand extends ArgumentCompletingCommand implements ProfileRepositoryAware, ResetableCommand {
public static final String ENCODING = System.getProperty("file.encoding") ?: "UTF-8"

protected static final String APPLICATION_YML = "application.yml"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import picocli.CommandLine.Model.CommandSpec
* @since 1.0
*/
@CompileStatic
abstract class ArgumentCompletingCommand implements ResetableCommand, Completer {
abstract class ArgumentCompletingCommand implements Command, Completer {

CommandSpec commandSpec

Expand All @@ -53,8 +53,4 @@ abstract class ArgumentCompletingCommand implements ResetableCommand, Completer
return new PicocliCompleter(commandSpec).complete(buffer, cursor, candidates)
}

@Override
void reset() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import io.micronaut.cli.profile.ProfileRepository
import io.micronaut.cli.profile.ProfileRepositoryAware
import io.micronaut.cli.profile.ProjectContext
import io.micronaut.cli.profile.ProjectContextAware
import io.micronaut.cli.profile.ResetableCommand
import picocli.CommandLine
import picocli.CommandLine.Model.CommandSpec

Expand Down Expand Up @@ -51,7 +52,7 @@ class HelpCommand implements ProfileCommand, ProjectContextAware, ProfileReposit

@CommandLine.Parameters(paramLabel = "COMMAND",
description = "The COMMAND to display the usage help message for.")
private String[] commands = new String[0];
private String[] commands = new String[0]

private CommandLine self
private PrintStream out
Expand Down Expand Up @@ -111,8 +112,4 @@ class HelpCommand implements ProfileCommand, ProjectContextAware, ProfileReposit
run()
}

@Override
void reset() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.micronaut.cli.profile.commands

import groovy.transform.CompileStatic
import io.micronaut.cli.profile.Command
import io.micronaut.cli.profile.ExecutionContext
import io.micronaut.cli.profile.Profile
import io.micronaut.cli.profile.ProfileRepository
Expand All @@ -32,7 +33,7 @@ import picocli.CommandLine.Model.CommandSpec
*/
@CompileStatic
@CommandLine.Command(name = 'list-profiles', description = 'Lists the available profiles')
class ListProfilesCommand implements ResetableCommand, ProfileRepositoryAware {
class ListProfilesCommand implements Command, ProfileRepositoryAware {

final String name = "list-profiles"

Expand Down Expand Up @@ -62,8 +63,4 @@ class ListProfilesCommand implements ResetableCommand, ProfileRepositoryAware {
return true
}

@Override
void reset() {

}
}

0 comments on commit 1ab5612

Please sign in to comment.