Use JCommander resolver in combination with others.

Prepare for implementation of describe()
This commit is contained in:
Eric Bottard
2017-06-22 16:06:19 +02:00
parent 14b2401374
commit e49ee885ef
12 changed files with 137 additions and 20 deletions

View File

@@ -0,0 +1,52 @@
/*
* Copyright 2017 the original author or authors.
*
* 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 org.springframework.shell2.samples.jcommander;
import java.util.ArrayList;
import java.util.List;
import com.beust.jcommander.Parameter;
/**
* An example straight from the JCommander documentation.
*
* @author Eric Bottard
* @author Cédric Beust
*/
public class Args {
@Parameter
private List<String> parameters = new ArrayList<>();
@Parameter(names = { "-log", "-verbose" }, description = "Level of verbosity")
private Integer verbose = 1;
@Parameter(names = "-groups", description = "Comma-separated list of group names to be run")
private String groups;
@Parameter(names = "-debug", description = "Debug mode")
private boolean debug = false;
@Override
public String toString() {
return "Args{" +
"parameters=" + parameters +
", verbose=" + verbose +
", groups='" + groups + '\'' +
", debug=" + debug +
'}';
}
}

View File

@@ -0,0 +1,35 @@
/*
* Copyright 2017 the original author or authors.
*
* 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 org.springframework.shell2.samples.jcommander;
import org.springframework.shell2.standard.ShellComponent;
import org.springframework.shell2.standard.ShellMethod;
import org.springframework.shell2.standard.ShellOption;
/**
* A class with JCommander commands.
*
* @author Eric Bottard
*/
@ShellComponent
public class JCommanderCommands {
@ShellMethod(help = "bind parameters to JCommander POJO")
public String jcommander(@ShellOption(optOut = true) Args args) {
return "You said " + args;
}
}