-
Notifications
You must be signed in to change notification settings - Fork 424
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
Hide the default System section from the HELP command #1429
Comments
Hi! |
Hi Remko, Here is how we build up the command registries. @Component
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
class NormalMode implements CliMode {
private MessageSource i18n
private Supplier<Path> pwd
private CommandLine parentCommandLine
@Autowired
NormalMode(
MessageSource messageSource,
@Qualifier("currentWorkingDir") Supplier<Path> pwd,
@Qualifier("rootCommandLine") CommandLine rootCommandLine,
SetupCommand setupCommand,
SetFactoryCommand setFactoryCommand,
ShowCommand showCommand,
ServiceCommand serviceCommand,
BackDoorCommand backDoorCommand
) {
this.i18n = messageSource
this.pwd = pwd
this.parentCommandLine = rootCommandLine
attachSubCommands(
rootCommandLine,
setupCommand,
setFactoryCommand,
showCommand,
serviceCommand,
backDoorCommand
)
}
protected void attachSubCommands(CommandLine commandLine, CliCommand<?>... subCommands) {
for (CliCommand<?> command : subCommands) {
commandLine.addSubcommand(command)
}
}
@Override
Supplier<String> supplyPromptString() {
return () -> i18n.getMessage("mode.normal.prompt", null, Locale.getDefault())
}
@Override
Supplier<Path> supplyCurrentWorkingDirectory() {
return pwd
}
@Override
CommandRegistry getCommandRegistry() {
return new PicocliCommands(pwd, parentCommandLine) {
@Override
String name() {
return i18n.getMessage("mode.normal.name", null, Locale.getDefault())
}
}
}
} Let me paste one of the command implementation here. @Component
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
@Command(name = "show",
subcommands = [
ShowInterfaceCommand,
ShowPm2ServiceCommand,
ShowSystemCommand,
CommandLine.HelpCommand ],
description = "Show system information")
@Slf4j
final class ShowCommand extends AbstractCliCommand<Integer> {
@Override
Integer call() throws Exception {
return 0
}
} At the point of reading the user's commands as shown below, we instantiate a @Override
void repl(CliMode mode) throws EndOfFileException, Exception {
SystemRegistry aggregator = new SystemRegistryImpl(parser, terminal, mode.supplyCurrentWorkingDirectory(),
null)
aggregator.setCommandRegistries(mode.getCommandRegistry())
LineReader lineReader = LineReaderBuilder
.builder()
.terminal(terminal)
.parser(parser)
.option(Option.CASE_INSENSITIVE, true)
.option(Option.AUTO_GROUP, false)
.option(Option.GROUP, false)
.completer(aggregator.completer()).variable(LineReader.LIST_MAX, 50).build()
while (true) {
try {
aggregator.cleanUp()
String line = lineReader.readLine(mode.supplyPromptString().get())
aggregator.execute(line)
} catch (UserInterruptException ctrlc) {
log.error("The user pressed Ctrl C.", ctrlc)
... We did not interfere with how the API will perform the root help behavior, that is, when we just type the Cheers, |
Oh I see now, this is a JLine3 application, that was not clear to me initially. Not sure if this is possible, but it may be. |
@allguitars it has been a while so it may not be on your radar any longer, but another suggestion I could make is to contact the JLine3 project and ask if they have any suggestions. |
@allguitars Is this still an issue for you or can I close this ticket? |
Hi,
I am currently working on a project where we have implemented a few custom commands. When I just type
help
command (without any subcommand), it displays two sections. One is the default System commands that are registered inherently showinghelp
andexit
commands. The other section shows our custom commands.However, our application is currently not supporting the
exit
command so we want to hide this part. How do I remove or hide the System section from the help menu?The text was updated successfully, but these errors were encountered: