001package org.unix4j.unix;
002
003import org.unix4j.command.CommandInterface;
004
005import org.unix4j.unix.cut.CutFactory;
006import org.unix4j.unix.cut.CutOption;
007import org.unix4j.unix.cut.CutOptions;
008import org.unix4j.unix.cut.CutOptionSets;
009
010/**
011 * Non-instantiable module with inner types making up the <b>cut</b> command.
012 * <p>
013 * <b>NAME</b>
014 * <p>
015 * cut - remove sections from each line of the input 
016 * <p>
017 * <b>SYNOPSIS</b>
018 * <p>
019 * <table>
020 * <tr><td width="10px"></td><td nowrap="nowrap">{@code cut <args>}</td></tr>
021 * <tr><td width="10px"></td><td nowrap="nowrap">{@code cut [-cf] <range>}</td></tr>
022 * <tr><td width="10px"></td><td nowrap="nowrap">{@code cut [-cf] <indexes>}</td></tr>
023 * <tr><td width="10px"></td><td nowrap="nowrap">{@code cut [-cf] <delimiter> <range>}</td></tr>
024 * <tr><td width="10px"></td><td nowrap="nowrap">{@code cut [-cf] <delimiter> <indexes>}</td></tr>
025 * <tr><td width="10px"></td><td nowrap="nowrap">{@code cut [-cf] <delimiter> <outputDelimiter> <range>}</td></tr>
026 * <tr><td width="10px"></td><td nowrap="nowrap">{@code cut [-cf] <delimiter> <outputDelimiter> <indexes>}</td></tr>
027 * </table>
028 * <p>
029 * See {@link Interface} for the corresponding command signature methods.
030 * <p>
031 * <b>DESCRIPTION</b>
032 * <p>
033 * <p>Print selected parts of lines from the input to the output.</p>
034 * 
035 * <p>
036 * <b>Options</b>
037 * <p>
038 * The following options are supported:
039 * <p>
040 * <table>
041 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -c}</td><td>&nbsp;&nbsp;</td><td nowrap="nowrap">{@code --chars}</td><td>&nbsp;</td><td>The list specifies character positions.</td></tr>
042 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -f}</td><td>&nbsp;&nbsp;</td><td nowrap="nowrap">{@code --fields}</td><td>&nbsp;</td><td>The list specifies fields, separated in the input by the field
043                        delimiter character (see the -d option.)  Output fields are
044                        separated by a single occurrence of the field delimiter character.</td></tr>
045 * </table>
046 * <p>
047 * <b>OPERANDS</b>
048 * <p>
049 * The following operands are supported:
050 * <p>
051 * <table>
052 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code <delimiter>}</td><td>&nbsp;:&nbsp;</td><td nowrap="nowrap">{@code String}</td><td>&nbsp;</td><td>use as the output delimiter the default is to use the input delimiter</td></tr>
053 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code <outputDelimiter>}</td><td>&nbsp;:&nbsp;</td><td nowrap="nowrap">{@code char}</td><td>&nbsp;</td><td>use as the output delimiter the default is to use the input delimiter</td></tr>
054 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code <indexes>}</td><td>&nbsp;:&nbsp;</td><td nowrap="nowrap">{@code int...}</td><td>&nbsp;</td><td>select these chars/field based on the given indexes. Indexes are 1 based.  i.e. the first character/field on a line has an index of 1.</td></tr>
055 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code <range>}</td><td>&nbsp;:&nbsp;</td><td nowrap="nowrap">{@code org.unix4j.util.Range}</td><td>&nbsp;</td><td>select only these fields</td></tr>
056 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code <args>}</td><td>&nbsp;:&nbsp;</td><td nowrap="nowrap">{@code String...}</td><td>&nbsp;</td><td>String arguments defining the options and operands for the command. 
057                        Options can be specified by acronym (with a leading dash "-") or by 
058                        long name (with two leading dashes "--"). Operands other than the
059                        default "--range" operand have to be prefixed with the operand name
060                        (e.g. "--indexes" for subsequent index operand values).</td></tr>
061 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code <options>}</td><td>&nbsp;:&nbsp;</td><td nowrap="nowrap">{@code CutOptions}</td><td>&nbsp;</td><td>options for the cut command</td></tr>
062 * </table>
063 */
064public final class Cut {
065        /**
066         * The "cut" command name.
067         */
068        public static final String NAME = "cut";
069
070        /**
071         * Interface defining all method signatures for the "cut" command.
072         * 
073         * @param <R>
074         *            the generic return type for all command signature methods
075         *            to support different implementor types; the methods of a 
076         *            command factory for instance returns a command instance; 
077         *            command builders can also implement this interface, but their
078         *            methods return the builder itself enabling for chained method
079         *            invocation to create joined commands
080         */
081        public static interface Interface<R> extends CommandInterface<R> {
082                /**
083                 * Cuts the fields or characters from the input line and writes them to 
084                        the standard output. Depending on the provided options and operands, 
085                        range, delimiter or indexes define the cut.
086                 *
087                 * @param args String arguments defining the options and operands for the command. 
088                        Options can be specified by acronym (with a leading dash "-") or by 
089                        long name (with two leading dashes "--"). Operands other than the
090                        default "--range" operand have to be prefixed with the operand name
091                        (e.g. "--indexes" for subsequent index operand values).
092                 * @return the generic type {@code <R>} defined by the implementing class;
093                 *         the command itself returns no value and writes its result to the
094                 *         standard output; see class level parameter comments for more 
095                 *         details
096                 */
097                R cut(String... args);
098                /**
099                 * Cuts the fields or characters using the given range
100                        from the input line and writes them to the output.
101                 *
102                 * @param options options for the cut command
103                 * @param range select only these fields
104                 * @return the generic type {@code <R>} defined by the implementing class;
105                 *         the command itself returns no value and writes its result to the
106                 *         standard output; see class level parameter comments for more 
107                 *         details
108                 */
109                R cut(CutOptions options, org.unix4j.util.Range range);
110                /**
111                 * Cuts the fields or characters using the given indexes
112                        from the input line and writes them to the output.
113                 *
114                 * @param options options for the cut command
115                 * @param indexes select these chars/field based on the given indexes. Indexes are 1 based.  i.e. the first character/field on a line has an index of 1.
116                 * @return the generic type {@code <R>} defined by the implementing class;
117                 *         the command itself returns no value and writes its result to the
118                 *         standard output; see class level parameter comments for more 
119                 *         details
120                 */
121                R cut(CutOptions options, int... indexes);
122                /**
123                 * Cuts the fields using the given range
124                        from the input line and writes them to the output.
125                 *
126                 * @param options options for the cut command
127                 * @param delimiter use as the output delimiter the default is to use the input delimiter
128                 * @param range select only these fields
129                 * @return the generic type {@code <R>} defined by the implementing class;
130                 *         the command itself returns no value and writes its result to the
131                 *         standard output; see class level parameter comments for more 
132                 *         details
133                 */
134                R cut(CutOptions options, String delimiter, org.unix4j.util.Range range);
135                /**
136                 * Cuts the fields using the given indexes
137                        from the input line and writes them to the output.
138                 *
139                 * @param options options for the cut command
140                 * @param delimiter use as the output delimiter the default is to use the input delimiter
141                 * @param indexes select these chars/field based on the given indexes. Indexes are 1 based.  i.e. the first character/field on a line has an index of 1.
142                 * @return the generic type {@code <R>} defined by the implementing class;
143                 *         the command itself returns no value and writes its result to the
144                 *         standard output; see class level parameter comments for more 
145                 *         details
146                 */
147                R cut(CutOptions options, String delimiter, int... indexes);
148                /**
149                 * Cuts the fields using the given range and using the given delimiter
150                        from the input line and writes them to the output using the given outputDelimiter.
151                 *
152                 * @param options options for the cut command
153                 * @param delimiter use as the output delimiter the default is to use the input delimiter
154                 * @param outputDelimiter use as the output delimiter the default is to use the input delimiter
155                 * @param range select only these fields
156                 * @return the generic type {@code <R>} defined by the implementing class;
157                 *         the command itself returns no value and writes its result to the
158                 *         standard output; see class level parameter comments for more 
159                 *         details
160                 */
161                R cut(CutOptions options, String delimiter, char outputDelimiter, org.unix4j.util.Range range);
162                /**
163                 * Cuts the fields using the given indexes and using the given delimiter
164                        from the input line and writes them to the output using the given outputDelimiter.
165                 *
166                 * @param options options for the cut command
167                 * @param delimiter use as the output delimiter the default is to use the input delimiter
168                 * @param outputDelimiter use as the output delimiter the default is to use the input delimiter
169                 * @param indexes select these chars/field based on the given indexes. Indexes are 1 based.  i.e. the first character/field on a line has an index of 1.
170                 * @return the generic type {@code <R>} defined by the implementing class;
171                 *         the command itself returns no value and writes its result to the
172                 *         standard output; see class level parameter comments for more 
173                 *         details
174                 */
175                R cut(CutOptions options, String delimiter, char outputDelimiter, int... indexes);
176        }
177
178        /**
179         * Options for the "cut" command: {@link CutOption#chars c}, {@link CutOption#fields f}.
180         * <p> 
181 * <table>
182 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -c}</td><td>&nbsp;&nbsp;</td><td nowrap="nowrap">{@code --chars}</td><td>&nbsp;</td><td>The list specifies character positions.</td></tr>
183 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -f}</td><td>&nbsp;&nbsp;</td><td nowrap="nowrap">{@code --fields}</td><td>&nbsp;</td><td>The list specifies fields, separated in the input by the field
184                        delimiter character (see the -d option.)  Output fields are
185                        separated by a single occurrence of the field delimiter character.</td></tr>
186 * </table>
187         */
188        public static final CutOptionSets Options = CutOptionSets.INSTANCE;
189
190        /**
191         * Singleton {@link CutFactory factory} instance for the "cut" command.
192         */
193        public static final CutFactory Factory = CutFactory.INSTANCE;
194
195        // no instances
196        private Cut() {
197                super();
198        }
199}