2020
2121from extractcode .api import extract_archives
2222
23- __version__ = '2020.09.21 '
23+ __version__ = '2021.6.1 '
2424
2525echo_stderr = functools .partial (click .secho , err = True )
2626
@@ -32,6 +32,34 @@ def print_version(ctx, param, value):
3232 ctx .exit ()
3333
3434
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+
3563info_text = '''
3664ExtractCode is a mostly universal archive and compressed files extractor, with
3765a particular focus on code archives.
@@ -120,9 +148,19 @@ class ExtractCommand(cliutils.BaseCommand):
120148@click .option (
121149 '--all-formats' ,
122150 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.' ,
124163)
125-
126164@click .help_option ('-h' , '--help' )
127165@click .option (
128166 '--about' ,
@@ -288,3 +326,4 @@ def get_relative_path(path, len_base_path, base_is_dir):
288326 rel_path = fileutils .file_name (path )
289327
290328 return rel_path .lstrip ('/' )
329+
0 commit comments