Skip to content

Commit 37a9d5f

Browse files
committed
Add new --list-formats CLI option #16
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
1 parent 5cf71db commit 37a9d5f

File tree

2 files changed

+49
-4
lines changed

2 files changed

+49
-4
lines changed

CHANGELOG.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@ v (next)
55
--------
66

77

8+
v21.6.2
9+
-------
10+
11+
- Add new --list-formats command line option to list supported archive formats
12+
13+
814
v21.6.1
9-
--------
15+
-------
1016

1117
- Add support for VMDK, QCOW and VDI VM image filesystems extraction
1218
- Add new configuration mechanism to get third-party binary paths:

src/extractcode/cli.py

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
from extractcode.api import extract_archives
2222

23-
__version__ = '2020.09.21'
23+
__version__ = '2021.6.1'
2424

2525
echo_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+
3563
info_text = '''
3664
ExtractCode is a mostly universal archive and compressed files extractor, with
3765
a 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

Comments
 (0)