Parse command-line arguments.
()
| 85 | |
| 86 | |
| 87 | def parse_arguments(): |
| 88 | """Parse command-line arguments.""" |
| 89 | parser = argparse.ArgumentParser(description="A simple Python cat command.") |
| 90 | |
| 91 | parser.add_argument( |
| 92 | "files", |
| 93 | nargs="*", |
| 94 | help="Files to read. Use '-' to read from standard input.", |
| 95 | ) |
| 96 | |
| 97 | parser.add_argument( |
| 98 | "-n", |
| 99 | "--number", |
| 100 | action="store_true", |
| 101 | help="Number all output lines.", |
| 102 | ) |
| 103 | |
| 104 | parser.add_argument( |
| 105 | "-b", |
| 106 | "--number-nonblank", |
| 107 | action="store_true", |
| 108 | help="Number non-empty output lines.", |
| 109 | ) |
| 110 | |
| 111 | parser.add_argument( |
| 112 | "-s", |
| 113 | "--squeeze-blank", |
| 114 | action="store_true", |
| 115 | help="Suppress repeated empty output lines.", |
| 116 | ) |
| 117 | |
| 118 | parser.add_argument( |
| 119 | "-E", |
| 120 | "--show-ends", |
| 121 | action="store_true", |
| 122 | help="Display $ at the end of each line.", |
| 123 | ) |
| 124 | |
| 125 | return parser.parse_args() |
| 126 | |
| 127 | |
| 128 | def main(): |