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,12 +49,23 @@ 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 , _path_for_url (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
54
- for path in args .path :
55
- client = _client_for_url (path )
56
- client .mkdirs (path , create_parent = create_parent )
66
+ for url in args .path :
67
+ client = _client_for_url (url )
68
+ client .mkdirs (_path_for_url ( url ) , create_parent = create_parent )
57
69
58
70
59
71
def mv (args : Namespace ):
@@ -69,7 +81,9 @@ def mv(args: Namespace):
69
81
pass
70
82
71
83
resolved_src = [
72
- path for pattern in args .src for path in _glob_path (client , pattern )
84
+ path
85
+ for pattern in args .src
86
+ for path in _glob_path (client , _path_for_url (pattern ))
73
87
]
74
88
75
89
if len (resolved_src ) > 1 and not dst_isdir :
@@ -95,6 +109,14 @@ def main(in_args: Optional[Sequence[str]] = None):
95
109
96
110
subparsers = parser .add_subparsers (title = "Subcommands" , required = True )
97
111
112
+ cat_parser = subparsers .add_parser (
113
+ "cat" ,
114
+ help = "Print the contents of a file" ,
115
+ description = "Print the contents of a file to stdout" ,
116
+ )
117
+ cat_parser .add_argument ("src" , nargs = "+" , help = "File pattern to print" )
118
+ cat_parser .set_defaults (func = cat )
119
+
98
120
mkdir_parser = subparsers .add_parser (
99
121
"mkdir" ,
100
122
help = "Create a directory" ,
0 commit comments