001package org.unix4j.unix; 002 003import org.unix4j.command.CommandInterface; 004 005import org.unix4j.unix.cat.CatFactory; 006import org.unix4j.unix.cat.CatOption; 007import org.unix4j.unix.cat.CatOptions; 008import org.unix4j.unix.cat.CatOptionSets; 009 010/** 011 * Non-instantiable module with inner types making up the <b>cat</b> command. 012 * <p> 013 * <b>NAME</b> 014 * <p> 015 * cat - concatenate and print files 016 * <p> 017 * <b>SYNOPSIS</b> 018 * <p> 019 * <table> 020 * <tr><td width="10px"></td><td nowrap="nowrap">{@code cat}</td></tr> 021 * <tr><td width="10px"></td><td nowrap="nowrap">{@code cat <args>}</td></tr> 022 * <tr><td width="10px"></td><td nowrap="nowrap">{@code cat <files>}</td></tr> 023 * <tr><td width="10px"></td><td nowrap="nowrap">{@code cat [-bns]}</td></tr> 024 * <tr><td width="10px"></td><td nowrap="nowrap">{@code cat [-bns] <files>}</td></tr> 025 * <tr><td width="10px"></td><td nowrap="nowrap">{@code cat [-bns] <paths>}</td></tr> 026 * </table> 027 * <p> 028 * See {@link Interface} for the corresponding command signature methods. 029 * <p> 030 * <b>DESCRIPTION</b> 031 * <p> 032 * <p> The cat utility reads files sequentially, writing them to the standard output. The file operands are processed in command-argument order. If no file argument is specified, cat reads from the standard input. </p> 033 * 034 * <p> 035 * <b>Options</b> 036 * <p> 037 * The following options are supported: 038 * <p> 039 * <table> 040 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -b}</td><td> </td><td nowrap="nowrap">{@code --numberNonBlankLines}</td><td> </td><td>Number the non-blank output lines, starting at 1.</td></tr> 041 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -n}</td><td> </td><td nowrap="nowrap">{@code --numberLines}</td><td> </td><td>Number the output lines, starting at 1.</td></tr> 042 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -s}</td><td> </td><td nowrap="nowrap">{@code --squeezeEmptyLines}</td><td> </td><td>Squeeze multiple adjacent empty lines, causing the output to be 043 single spaced.</td></tr> 044 * </table> 045 * <p> 046 * <b>OPERANDS</b> 047 * <p> 048 * The following operands are supported: 049 * <p> 050 * <table> 051 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code <files>}</td><td> : </td><td nowrap="nowrap">{@code java.io.File...}</td><td> </td><td>The input files to be printed; relative paths are not resolved (use 052 the string path argument to enable relative path resolving based on 053 the current working directory).</td></tr> 054 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code <paths>}</td><td> : </td><td nowrap="nowrap">{@code String...}</td><td> </td><td>Pathnames of the input files to be printed; wildcards * and ? are 055 supported; relative paths are resolved on the basis of the current 056 working directory.</td></tr> 057 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code <args>}</td><td> : </td><td nowrap="nowrap">{@code String...}</td><td> </td><td>String arguments defining the options and file operands for the 058 command. Options can be specified by acronym (with a leading dash 059 "-") or by long name (with two leading dashes "--"). File arguments 060 are expanded if wildcards are used.</td></tr> 061 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code <options>}</td><td> : </td><td nowrap="nowrap">{@code CatOptions}</td><td> </td><td>Options for the cat command.</td></tr> 062 * </table> 063 */ 064public final class Cat { 065 /** 066 * The "cat" command name. 067 */ 068 public static final String NAME = "cat"; 069 070 /** 071 * Interface defining all method signatures for the "cat" 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 * Reads the lines from the standard input and writes them to the 084 standard output. 085 * 086 * @return the generic type {@code <R>} defined by the implementing class; 087 * the command itself returns no value and writes its result to the 088 * standard output; see class level parameter comments for more 089 * details 090 */ 091 R cat(); 092 /** 093 * Reads the lines from files specified as arguments and writes them to 094 the standard output. Options can be specified by acronym (with a 095 leading dash "-") or by long name (with two leading dashes "--"). 096 File arguments are expanded if wildcards are used. All file 097 arguments are processed in command-argument order. 098 * 099 * @param args String arguments defining the options and file operands for the 100 command. Options can be specified by acronym (with a leading dash 101 "-") or by long name (with two leading dashes "--"). File arguments 102 are expanded if wildcards are used. 103 * @return the generic type {@code <R>} defined by the implementing class; 104 * the command itself returns no value and writes its result to the 105 * standard output; see class level parameter comments for more 106 * details 107 */ 108 R cat(String... args); 109 /** 110 * Reads the lines from the specified files and writes them to the 111 standard output. The files are processed in command-argument order. 112 * 113 * @param files The input files to be printed; relative paths are not resolved (use 114 the string path argument to enable relative path resolving based on 115 the current working directory). 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 cat(java.io.File... files); 122 /** 123 * Reads the lines from the standard input and writes them to the 124 standard output; the given options define the details of the output 125 format. 126 * 127 * @param options Options for the cat command. 128 * @return the generic type {@code <R>} defined by the implementing class; 129 * the command itself returns no value and writes its result to the 130 * standard output; see class level parameter comments for more 131 * details 132 */ 133 R cat(CatOptions options); 134 /** 135 * Reads the lines from the specified files and writes them to the 136 standard output; the given options define the details of the output 137 format. The files are processed in command-argument order. 138 * 139 * @param options Options for the cat command. 140 * @param files The input files to be printed; relative paths are not resolved (use 141 the string path argument to enable relative path resolving based on 142 the current working directory). 143 * @return the generic type {@code <R>} defined by the implementing class; 144 * the command itself returns no value and writes its result to the 145 * standard output; see class level parameter comments for more 146 * details 147 */ 148 R cat(CatOptions options, java.io.File... files); 149 /** 150 * Reads the lines from the specified files and writes them to the 151 standard output; the given options define the details of the output 152 format. The path arguments are expanded if wildcards are used and 153 processed in command-argument order. 154 * 155 * @param options Options for the cat command. 156 * @param paths Pathnames of the input files to be printed; wildcards * and ? are 157 supported; relative paths are resolved on the basis of the current 158 working directory. 159 * @return the generic type {@code <R>} defined by the implementing class; 160 * the command itself returns no value and writes its result to the 161 * standard output; see class level parameter comments for more 162 * details 163 */ 164 R cat(CatOptions options, String... paths); 165 } 166 167 /** 168 * Options for the "cat" command: {@link CatOption#numberNonBlankLines b}, {@link CatOption#numberLines n}, {@link CatOption#squeezeEmptyLines s}. 169 * <p> 170 * <table> 171 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -b}</td><td> </td><td nowrap="nowrap">{@code --numberNonBlankLines}</td><td> </td><td>Number the non-blank output lines, starting at 1.</td></tr> 172 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -n}</td><td> </td><td nowrap="nowrap">{@code --numberLines}</td><td> </td><td>Number the output lines, starting at 1.</td></tr> 173 * <tr valign="top"><td width="10px"></td><td nowrap="nowrap">{@code -s}</td><td> </td><td nowrap="nowrap">{@code --squeezeEmptyLines}</td><td> </td><td>Squeeze multiple adjacent empty lines, causing the output to be 174 single spaced.</td></tr> 175 * </table> 176 */ 177 public static final CatOptionSets Options = CatOptionSets.INSTANCE; 178 179 /** 180 * Singleton {@link CatFactory factory} instance for the "cat" command. 181 */ 182 public static final CatFactory Factory = CatFactory.INSTANCE; 183 184 // no instances 185 private Cat() { 186 super(); 187 } 188}