Add cli commands for users and groups (#1993)

Adds cli commands to manage users and groups.

Co-authored-by: Matthias Thieroff <matthias.thieroff@cloudogu.com>
This commit is contained in:
René Pfeuffer
2022-04-11 10:04:19 +02:00
committed by GitHub
parent edd972b1a8
commit d2e81ce121
51 changed files with 4640 additions and 12 deletions

View File

@@ -111,7 +111,15 @@ public class TemplateRenderer {
* @return table for templating content
*/
public Table createTable() {
return new Table(getSpecOrDie().resourceBundle());
return new Table(getBundle());
}
protected CliContext getContext() {
return context;
}
protected ResourceBundle getBundle() {
return getSpecOrDie().resourceBundle();
}
private CommandLine.Model.CommandSpec getSpecOrDie() {
@@ -137,7 +145,7 @@ public class TemplateRenderer {
UnaryOperator<String> upper = value -> value.toUpperCase(context.getLocale());
finalModel.put("upper", upper);
ResourceBundle resourceBundle = getSpecOrDie().resourceBundle();
ResourceBundle resourceBundle = getBundle();
if (resourceBundle != null) {
finalModel.put("i18n", new I18n(resourceBundle));
}

View File

@@ -0,0 +1,30 @@
/*
* MIT License
*
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.repository.cli;
import picocli.CommandLine;
@CommandLine.Command(name = "group")
public class GroupCommand {}

View File

@@ -0,0 +1,30 @@
/*
* MIT License
*
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.user.cli;
import picocli.CommandLine;
@CommandLine.Command(name = "user")
public class UserCommand {}

View File

@@ -49,7 +49,12 @@ class CommandValidatorTest {
@Test
void shouldValidateCommand() {
ResourceBundle resourceBundle = ResourceBundle.getBundle("sonia.scm.cli.i18n", Locale.ENGLISH);
ResourceBundle resourceBundle = ResourceBundle.getBundle("sonia.scm.cli.i18n", Locale.ENGLISH, new ResourceBundle.Control() {
@Override
public Locale getFallbackLocale(String baseName, Locale locale) {
return Locale.ROOT;
}
});
when(context.getLocale()).thenReturn(Locale.ENGLISH);
CommandLine commandLine = new CommandLine(Command.class, new TestingCommandFactory());
commandLine.setResourceBundle(resourceBundle);
@@ -63,7 +68,12 @@ class CommandValidatorTest {
@Test
void shouldValidateCommandWithGermanLocale() {
ResourceBundle resourceBundle = ResourceBundle.getBundle("sonia.scm.cli.i18n", Locale.GERMAN);
ResourceBundle resourceBundle = ResourceBundle.getBundle("sonia.scm.cli.i18n", Locale.GERMAN, new ResourceBundle.Control() {
@Override
public Locale getFallbackLocale(String baseName, Locale locale) {
return Locale.ROOT;
}
});
when(context.getLocale()).thenReturn(Locale.GERMAN);
CommandLine commandLine = new CommandLine(Command.class, new TestingCommandFactory());
commandLine.setResourceBundle(resourceBundle);
@@ -79,7 +89,7 @@ class CommandValidatorTest {
public static class Command implements Runnable {
@CommandLine.Mixin
private CommandValidator commandValidator;
private final CommandValidator commandValidator;
@Email
@CommandLine.Option(names = "--mail")