20
20
21
21
from extractcode .api import extract_archives
22
22
23
- __version__ = '2020.09.21 '
23
+ __version__ = '2021.6.1 '
24
24
25
25
echo_stderr = functools .partial (click .secho , err = True )
26
26
@@ -32,6 +32,34 @@ def print_version(ctx, param, value):
32
32
ctx .exit ()
33
33
34
34
35
+ def print_archive_formats (ctx , param , value ):
36
+ from itertools import groupby
37
+ from extractcode import kind_labels
38
+ from extractcode .archive import archive_handlers
39
+
40
+ if not value or ctx .resilient_parsing :
41
+ return
42
+
43
+ kindkey = lambda x :x .kind
44
+
45
+ by_kind = groupby (sorted (archive_handlers , key = kindkey ), key = kindkey )
46
+
47
+ for kind , handlers in by_kind :
48
+ click .echo ('--------------------------------------------' )
49
+ click .echo (f'Archives of kind: { kind_labels [kind ]} ' )
50
+ for handler in handlers :
51
+ exts = ', ' .join (handler .extensions )
52
+ mimes = ', ' .join (handler .mimetypes )
53
+ types = ', ' .join (handler .filetypes )
54
+ click .echo (f' name: { handler .name } ' )
55
+ click .echo (f' extensions: { exts } ' )
56
+ click .echo (f' filetypes : { types } ' )
57
+ click .echo (f' mimetypes : { mimes } ' )
58
+ click .echo ('' )
59
+
60
+ ctx .exit ()
61
+
62
+
35
63
info_text = '''
36
64
ExtractCode is a mostly universal archive and compressed files extractor, with
37
65
a particular focus on code archives.
@@ -120,9 +148,19 @@ class ExtractCommand(cliutils.BaseCommand):
120
148
@click .option (
121
149
'--all-formats' ,
122
150
is_flag = True ,
123
- help = 'Extract archives from all known formats.' ,
151
+ help =
152
+ 'Extract archives from all known formats. '
153
+ 'The default is to extract only the common format of these kinds: '
154
+ '"regular", "regular_nested" and "package". '
155
+ 'To show all supported formats use the option --list-formats .' ,
156
+ )
157
+ @click .option (
158
+ '--list-formats' ,
159
+ is_flag = True ,
160
+ is_eager = True ,
161
+ callback = print_archive_formats ,
162
+ help = 'Show the list of supported archive and compressed file formats and exit.' ,
124
163
)
125
-
126
164
@click .help_option ('-h' , '--help' )
127
165
@click .option (
128
166
'--about' ,
@@ -288,3 +326,4 @@ def get_relative_path(path, len_base_path, base_is_dir):
288
326
rel_path = fileutils .file_name (path )
289
327
290
328
return rel_path .lstrip ('/' )
329
+
0 commit comments