|
1 | 1 | import functools
|
2 | 2 | import os
|
| 3 | +import sys |
3 | 4 | from argparse import ArgumentParser, Namespace
|
4 | 5 | from typing import List, Optional, Sequence
|
5 | 6 | from urllib.parse import urlparse
|
@@ -48,6 +49,17 @@ def _glob_path(client: Client, glob: str) -> List[str]:
|
48 | 49 | return [glob]
|
49 | 50 |
|
50 | 51 |
|
| 52 | +def cat(args: Namespace): |
| 53 | + for src in args.src: |
| 54 | + client = _client_for_url(src) |
| 55 | + for path in _glob_path(client, src): |
| 56 | + with client.read(path) as file: |
| 57 | + while chunk := file.read(1024 * 1024): |
| 58 | + sys.stdout.buffer.write(chunk) |
| 59 | + |
| 60 | + sys.stdout.buffer.flush() |
| 61 | + |
| 62 | + |
51 | 63 | def mkdir(args: Namespace):
|
52 | 64 | create_parent = args.parent
|
53 | 65 |
|
@@ -95,6 +107,14 @@ def main(in_args: Optional[Sequence[str]] = None):
|
95 | 107 |
|
96 | 108 | subparsers = parser.add_subparsers(title="Subcommands", required=True)
|
97 | 109 |
|
| 110 | + cat_parser = subparsers.add_parser( |
| 111 | + "cat", |
| 112 | + help="Print the contents of a file", |
| 113 | + description="Print the contents of a file to stdout", |
| 114 | + ) |
| 115 | + cat_parser.add_argument("src", nargs="+", help="File pattern to print") |
| 116 | + cat_parser.set_defaults(func=cat) |
| 117 | + |
98 | 118 | mkdir_parser = subparsers.add_parser(
|
99 | 119 | "mkdir",
|
100 | 120 | help="Create a directory",
|
|
0 commit comments