public final class GrepArguments extends Object implements Arguments<GrepArguments>
grep command.| Constructor and Description |
|---|
GrepArguments()
Constructor to use if no options are specified.
|
GrepArguments(GrepOptions options)
Constructor with option set containing the selected command options.
|
GrepArguments(String... args)
Constructor string arguments encoding options and arguments, possibly
also containing variable expressions.
|
| Modifier and Type | Method and Description |
|---|---|
String[] |
getArgs()
Returns the
<args> operand value: String arguments defining the options and operands for the command. |
File[] |
getFiles()
Returns the
<files> operand value: The input files to be searched for the pattern; relative paths are
not resolved (use the string paths argument to enable relative path
resolving based on the current working directory). |
GrepArguments |
getForContext(ExecutionContext context)
Returns an arguments object for the given execution context with resolved
variables if necessary and possible.
|
GrepOptions |
getOptions()
Returns the options set containing the selected command options.
|
String[] |
getPaths()
Returns the
<paths> operand value: Pathnames of the input files to be searched for the pattern;
wildcards * and ? are supported; relative paths are resolved on the
basis of the current working directory. |
Pattern |
getPattern()
Returns the
<pattern> operand value: Lines will be printed which match the given pattern. |
String |
getRegexp()
Returns the
<regexp> operand value (variables are NOT resolved): Lines will be printed which match the given regular expression. |
String |
getRegexp(ExecutionContext context)
Returns the
<regexp> (variables are resolved): Lines will be printed which match the given regular expression. |
boolean |
isArgsSet()
Returns true if the
<args> operand has been set. |
boolean |
isCount()
Returns true if the
--count option
is set. |
boolean |
isFilesSet()
Returns true if the
<files> operand has been set. |
boolean |
isFixedStrings()
Returns true if the
--fixedStrings option
is set. |
boolean |
isIgnoreCase()
Returns true if the
--ignoreCase option
is set. |
boolean |
isInvertMatch()
Returns true if the
--invertMatch option
is set. |
boolean |
isLineNumber()
Returns true if the
--lineNumber option
is set. |
boolean |
isMatchingFiles()
Returns true if the
--matchingFiles option
is set. |
boolean |
isPathsSet()
Returns true if the
<paths> operand has been set. |
boolean |
isPatternSet()
Returns true if the
<pattern> operand has been set. |
boolean |
isRegexpSet()
Returns true if the
<regexp> operand has been set. |
boolean |
isWholeLine()
Returns true if the
--wholeLine option
is set. |
void |
setFiles(File... files)
Sets
<files>: The input files to be searched for the pattern; relative paths are
not resolved (use the string paths argument to enable relative path
resolving based on the current working directory). |
void |
setPaths(String... paths)
Sets
<paths>: Pathnames of the input files to be searched for the pattern;
wildcards * and ? are supported; relative paths are resolved on the
basis of the current working directory. |
void |
setPattern(Pattern pattern)
Sets
<pattern>: Lines will be printed which match the given pattern. |
void |
setRegexp(String regexp)
Sets
<regexp>: Lines will be printed which match the given regular expression. |
String |
toString()
Returns a string representation of the command arguments and options.
|
public GrepArguments()
public GrepArguments(GrepOptions options)
options - the selected optionsNullPointerException - if the argument is nullpublic GrepArguments(String... args)
args - string arguments for the commandNullPointerException - if args is nullpublic GrepOptions getOptions()
public GrepArguments getForContext(ExecutionContext context)
Argumentsthis arguments instance is simply returned.
If variables are present, they are resolved if such a variable is defined
in the VariableContext returned by
context.getVariableContext().
Values are converted if necessary with the ValueConverters
returned by
context.getValueConverterFor(Class).
getForContext in interface Arguments<GrepArguments>context - the execution context providing access to variables and
converterspublic String getRegexp()
<regexp> operand value (variables are NOT resolved): Lines will be printed which match the given regular expression. The
regexp string is surrounded with ".*" on both sides unless
the --wholeLine option is specified. If the
--fixedStrings option is used, plain string comparison is
used instead of regular expression matching.<regexp> operand value (variables are not resolved)IllegalStateException - if this operand has never been setgetRegexp(ExecutionContext)public String getRegexp(ExecutionContext context)
<regexp> (variables are resolved): Lines will be printed which match the given regular expression. The
regexp string is surrounded with ".*" on both sides unless
the --wholeLine option is specified. If the
--fixedStrings option is used, plain string comparison is
used instead of regular expression matching.context - the execution context used to resolve variables<regexp> operand value after resolving variablesIllegalStateException - if this operand has never been setgetRegexp()public boolean isRegexpSet()
<regexp> operand has been set.
Note that this method returns true even if null was passed to the
setRegexp(String) method.
<regexp> operand has
been called at least oncepublic void setRegexp(String regexp)
<regexp>: Lines will be printed which match the given regular expression. The
regexp string is surrounded with ".*" on both sides unless
the --wholeLine option is specified. If the
--fixedStrings option is used, plain string comparison is
used instead of regular expression matching.regexp - the value for the <regexp> operandpublic Pattern getPattern()
<pattern> operand value: Lines will be printed which match the given pattern.<pattern> operand value (variables are not resolved)IllegalStateException - if this operand has never been setpublic boolean isPatternSet()
<pattern> operand has been set.
Note that this method returns true even if null was passed to the
setPattern(java.util.regex.Pattern) method.
<pattern> operand has
been called at least oncepublic void setPattern(Pattern pattern)
<pattern>: Lines will be printed which match the given pattern.pattern - the value for the <pattern> operandpublic String[] getPaths()
<paths> operand value: Pathnames of the input files to be searched for the pattern;
wildcards * and ? are supported; relative paths are resolved on the
basis of the current working directory.<paths> operand value (variables are not resolved)IllegalStateException - if this operand has never been setpublic boolean isPathsSet()
<paths> operand has been set.
Note that this method returns true even if null was passed to the
setPaths(String[]) method.
<paths> operand has
been called at least oncepublic void setPaths(String... paths)
<paths>: Pathnames of the input files to be searched for the pattern;
wildcards * and ? are supported; relative paths are resolved on the
basis of the current working directory.paths - the value for the <paths> operandpublic File[] getFiles()
<files> operand value: The input files to be searched for the pattern; relative paths are
not resolved (use the string paths argument to enable relative path
resolving based on the current working directory).<files> operand value (variables are not resolved)IllegalStateException - if this operand has never been setpublic boolean isFilesSet()
<files> operand has been set.
Note that this method returns true even if null was passed to the
setFiles(java.io.File[]) method.
<files> operand has
been called at least oncepublic void setFiles(File... files)
<files>: The input files to be searched for the pattern; relative paths are
not resolved (use the string paths argument to enable relative path
resolving based on the current working directory).files - the value for the <files> operandpublic String[] getArgs()
<args> operand value: String arguments defining the options and operands for the command.
Options can be specified by acronym (with a leading dash "-") or by
long name (with two leading dashes "--"). Operands other than the
default "--pattern" and "--paths" operands have to be prefixed with
the operand name (e.g. "--files" for subsequent file operand values).<args> operand value (variables are not resolved)IllegalStateException - if this operand has never been setpublic boolean isArgsSet()
<args> operand has been set.<args> operand has
been called at least oncepublic boolean isIgnoreCase()
--ignoreCase option
is set. The option is also known as -i option.
Description: Match lines ignoring the case when comparing the strings, also known from Unix with its acronym 'i'.
--ignoreCase or -i option is setpublic boolean isInvertMatch()
--invertMatch option
is set. The option is also known as -v option.
Description: Invert the match result, that is, a non-matching line is written to the output and a matching line is not. This option is also known from Unix with its acronym 'v'.
--invertMatch or -v option is setpublic boolean isFixedStrings()
--fixedStrings option
is set. The option is also known as -F option.
Description: Use fixed-strings matching instead of regular expressions. This is usually faster than the standard regexp version.
(This option is ignored if a pattern operand is specified
instead of the regexp string).
--fixedStrings or -F option is setpublic boolean isLineNumber()
--lineNumber option
is set. The option is also known as -n option.
Description: Prefix each line of output with the line number within its input file.
--lineNumber or -n option is setpublic boolean isCount()
--count option
is set. The option is also known as -c option.
Description: Suppress normal output; instead print a count of matching lines for
each input file. With the -v, --invertMatch option,
count non-matching lines.
--count or -c option is setpublic boolean isMatchingFiles()
--matchingFiles option
is set. The option is also known as -l option.
Description: Suppress normal output; instead print the name of each input file from which output would normally have been printed. The scanning will stop on the first match.
--matchingFiles or -l option is setpublic boolean isWholeLine()
--wholeLine option
is set. The option is also known as -x option.
Description: Select only those matches that exactly match the whole line excluding the terminating line ending.
(This option is ignored if a pattern operand is specified
instead of the regexp string).
--wholeLine or -x option is setpublic String toString()
ArgumentstoString in interface Arguments<GrepArguments>toString in class ObjectCopyright © 2017. All Rights Reserved.