Skip to content

Commit

Permalink
enable to filter command in help command
Browse files Browse the repository at this point in the history
  • Loading branch information
rmannibucau committed Feb 18, 2021
1 parent 4ebf6e0 commit a63b086
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public class HelpCommand implements Executable {
@Inject
private BeanManager beanManager;

@Inject
@Description("Which command to show help for.")
@ConfigProperty(name = "bundlebee.help.command", defaultValue = "")
private String command;

@Override
public String name() {
return "help";
Expand All @@ -65,6 +70,7 @@ public CompletionStage<?> execute() {
" BundleBee is a light Kubernetes package manager. Available commands:\n" +
"\n" +
stream(executables)
.filter(it -> command.isBlank() || command.equals(it.name()))
.map(executable -> {
final var parameters = findParameters(executable).collect(toList());
final var desc = reflowText(executable.description()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2021 - Yupiik SAS - https://www.yupiik.com
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.yupiik.bundlebee.core.command.impl;

import io.yupiik.bundlebee.core.BundleBee;
import io.yupiik.bundlebee.core.test.BundleBeeExtension;
import io.yupiik.bundlebee.core.test.CommandExecutor;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import static java.util.logging.Level.INFO;
import static org.junit.jupiter.api.Assertions.assertEquals;

class HelpCommandTest { // BundleBeeTest already test help command (since it is always there)
@RegisterExtension
BundleBeeExtension extension = new BundleBeeExtension();

@Test
void helpOneCommand(final CommandExecutor executor) {
final var logs = executor.wrap(INFO, () -> new BundleBee().launch("help", "--command", "version"));
assertEquals("" +
"\n" +
"BundleBee\n" +
"\n" +
" BundleBee is a light Kubernetes package manager. Available commands:\n" +
"\n" +
" [] version: shows the application version.\n" +
"\n" +
"\n" +
"", logs);
}
}

0 comments on commit a63b086

Please # to comment.