All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.unix4j.unix.xargs.XargsOption Maven / Gradle / Ivy

There is a newer version: 0.6
Show newest version
package org.unix4j.unix.xargs;

import java.util.Collections;
import java.util.EnumSet;
import java.util.Iterator;

import org.unix4j.option.Option;
import org.unix4j.unix.Xargs;

/**
 * Options for the {@link Xargs xargs} command.
 * 

* For most applications, it may be more convenient to use {@link Xargs#Options} * instead of the option constants defined here. *

*

* * * * *
{@code -z}  {@code --delimiter0} Input items are terminated by a null character instead of by whitespace, and the quotes and backslash are not special (every character is taken literally). Disables the end of file string, which is treated like any other argument. Useful when input items might contain white space, quote marks, or backslashes. The find --print0 option produces input suitable for this mode.

(This option is ignored if an explicit delimiter operand is specified).

{@code -x}  {@code --exactArgs} Terminate immediately if {@code maxArgs} is specified but the found number of variable items is less than {@code maxArgs}.

(This option is ignored if no {@code maxArgs} operand is specified).

{@code -r}  {@code --noRunIfEmpty} If the standard input does not contain any nonblanks, do not run the command. Normally, the command is run once even if there is no input.
{@code -t}  {@code --verbose} Print the command line on the standard error output before executing it.
*/ public enum XargsOption implements Option, XargsOptions { /** * Option {@code --delimiter0}, {@code -z}: * Input items are terminated by a null character instead of by whitespace, and the quotes and backslash are not special (every character is taken literally). Disables the end of file string, which is treated like any other argument. Useful when input items might contain white space, quote marks, or backslashes. The find --print0 option produces input suitable for this mode.

(This option is ignored if an explicit delimiter operand is specified). */ delimiter0('z'), /** * Option {@code --exactArgs}, {@code -x}: * Terminate immediately if {@code maxArgs} is specified but the found number of variable items is less than {@code maxArgs}.

(This option is ignored if no {@code maxArgs} operand is specified). */ exactArgs('x'), /** * Option {@code --noRunIfEmpty}, {@code -r}: * If the standard input does not contain any nonblanks, do not run the command. Normally, the command is run once even if there is no input. */ noRunIfEmpty('r'), /** * Option {@code --verbose}, {@code -t}: * Print the command line on the standard error output before executing it. */ verbose('t'); private final char acronym; private XargsOption(char acronym) { this.acronym = acronym; } @Override public Class optionType() { return XargsOption.class; } /** * Returns the option with the given {@code acronym}, or {@code null} if no * such option is found. * * @param acronym the option {@link #acronym() acronym} * @return the option with the given {@code acronym} or {@code null} if it * is not found */ public static XargsOption findByAcronym(char acronym) { for (final XargsOption opt : values()) { if (opt.acronym() == acronym) return opt; } return null; } @Override public char acronym() { return acronym; } @Override public boolean isSet(XargsOption option) { return equals(option); } /** * Returns a new set with {@code this} active option. * * @return a new set containing this option */ @Override public EnumSet asSet() { return EnumSet.of(this); } /** * Returns an immutable iterator returning o single element: {@code this} * option. * * @return an immutable iterator with {@code this} active option. */ @Override public Iterator iterator() { return Collections.singleton(this).iterator(); } /** * Returns 1 as this is a set with a single element: {@code this} option * * @return one */ @Override public int size() { return 1; } /** * Returns true if the {@link Option#acronym() acronym} should be used for * the specified {@code option} in string representations. *

* This method returns always true for all options. * * @param option * the option of interest * @return always true indicating that option acronyms should be used in * string representations for all options */ @Override public boolean useAcronymFor(XargsOption option) { return true; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy