![JAR search and dependency download from the Maven repository](/logo.png)
org.unix4j.unix.echo.EchoArguments Maven / Gradle / Ivy
package org.unix4j.unix.echo;
import java.util.List;
import java.util.Map;
import java.util.Arrays;
import org.unix4j.command.Arguments;
import org.unix4j.context.ExecutionContext;
import org.unix4j.convert.ValueConverter;
import org.unix4j.option.DefaultOptionSet;
import org.unix4j.util.ArgsUtil;
import org.unix4j.util.ArrayUtil;
import org.unix4j.variable.Arg;
import org.unix4j.variable.VariableContext;
import org.unix4j.unix.Echo;
/**
* Arguments and options for the {@link Echo echo} command.
*/
public final class EchoArguments implements Arguments {
private final EchoOptions options;
// operand:
private String string;
private boolean stringIsSet = false;
// operand:
private String[] strings;
private boolean stringsIsSet = false;
// operand:
private String[] args;
private boolean argsIsSet = false;
/**
* Constructor to use if no options are specified.
*/
public EchoArguments() {
this.options = EchoOptions.EMPTY;
}
/**
* Constructor with option set containing the selected command options.
*
* @param options the selected options
* @throws NullPointerException if the argument is null
*/
public EchoArguments(EchoOptions options) {
if (options == null) {
throw new NullPointerException("options argument cannot be null");
}
this.options = options;
}
/**
* Returns the options set containing the selected command options. Returns
* an empty options set if no option has been selected.
*
* @return set with the selected options
*/
public EchoOptions getOptions() {
return options;
}
/**
* Constructor string arguments encoding options and arguments, possibly
* also containing variable expressions.
*
* @param args string arguments for the command
* @throws NullPointerException if args is null
*/
public EchoArguments(String... args) {
this();
this.args = args;
this.argsIsSet = true;
}
private Object[] resolveVariables(VariableContext context, String... unresolved) {
final Object[] resolved = new Object[unresolved.length];
for (int i = 0; i < resolved.length; i++) {
final String expression = unresolved[i];
if (Arg.isVariable(expression)) {
resolved[i] = resolveVariable(context, expression);
} else {
resolved[i] = expression;
}
}
return resolved;
}
private V convertList(ExecutionContext context, String operandName, Class operandType, List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy