Skip to content

Commit 5690c88

Browse files
committed
Refined command help texts.
1 parent ba945f9 commit 5690c88

File tree

2 files changed

+63
-43
lines changed

2 files changed

+63
-43
lines changed

samples/arch/zlib.tar.gz

27.4 KB
Binary file not shown.

src/scancode/cli.py

Lines changed: 63 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282

8383

8484
extra_notice_text = '''
85+
8586
Third-party software licenses
8687
=============================
8788
@@ -122,37 +123,48 @@ def print_about(ctx, param, value):
122123
examples_text = '''
123124
Scancode command lines examples:
124125
125-
(Note for Windows: use '\' backward slashes instead of '/' forward slashes.)
126+
(Note for Windows: use '\\' back slash instead of '/' forward slash for paths.)
127+
128+
Scan the 'samples' directory for licenses and copyrights. Save scan results to
129+
an HTML app file for interactive scan results navigation. When the scan is done,
130+
open 'scancode_result.html' in your web browser. Note that additional app files
131+
are saved in a directory named 'scancode_result_files':
126132
127-
Scan a directory for licenses and copyrights. Save scan results to an HTML app
128-
file for interactive scan results navigation. Additional app files are saved in
129-
the directory 'scancode_result_files':
130-
scancode --format html-app mydir/ scancode_result.html
133+
scancode --format html-app samples/ scancode_result.html
131134
132-
Scan a directory for licenses and copyrights (default). Save scan results to an
135+
Scan a directory for licenses and copyrights. Save scan results to an
133136
HTML file:
134-
scancode --format html mydir/ scancode_result.html
137+
138+
scancode --format html samples/zlib scancode_result.html
135139
136140
Scan a single file for copyrights. Print scan results on terminal as JSON:
137-
scancode -copyright myfile.c
138141
139-
Scan a directory for licenses and copyrights. Redirect scan results to a file:
140-
scancode -f json code-dir > scan.json
142+
scancode --copyright samples/zlib/zlib.h
143+
144+
Scan a single file for licenses, print verbose progress on terminal as each file
145+
is scanned. Save scan to a JSON file:
146+
147+
scancode --license --verbose samples/zlib/zlib.h licenses.json
148+
149+
Scan a directory explicitly for licenses and copyrights. Redirect JSON scan
150+
results to a file:
151+
152+
scancode -f json -l -c samples/zlib/ > scan.json
141153
142-
Scan a single file for licenses. Save scan to a JSON file:
143-
scancode -l myfile.c licenses.json
154+
Extract all archives found in the 'samples' directory tree:
144155
145-
Extract all archives found in the 'mydir' directory tree.
146-
scancode --extract mydir
147-
Note: The extraction is recursive: if an archive contains other archives, all
148-
will be extracted. Extraction is performed directly in 'mydir', side-by-side
149-
with each archive. Files are extracted in a directory named after the archive
150-
with an '-extract' suffix added. This directory is created side-by-side with
151-
each archive file.
156+
scancode --extract samples
157+
158+
Note: If an archive contains other archives, all contained archives will be
159+
extracted recursively. Extraction is done directly in the 'samples' directory,
160+
side-by-side with each archive. Files are extracted in a directory named after
161+
the archive with an '-extract' suffix added to its name, created side-by-side
162+
with the corresponding archive file.
152163
153164
Extract a single archive. Files are extracted in the directory
154-
'mydir/zlib-1.2.8.tar.gz-extract/':
155-
scancode --extract mydir/zlib-1.2.8.tar.gz
165+
'samples/arch/zlib.tar.gz-extract/':
166+
167+
scancode --extract samples/arch/zlib.tar.gz
156168
'''
157169

158170

@@ -173,21 +185,25 @@ def print_version(ctx, param, value):
173185
epilog_text = '''\b\bExamples (use --examples for more):
174186
175187
\b
176-
Scan 'mydir' directory for licenses and copyrights. Save scan results to a JSON file:
188+
Scan the 'samples' directory for licenses and copyrights.
189+
Save scan results to a JSON file:
177190
178-
scancode --format json mydir scancode_result.json
191+
scancode --format json samples scancode_result.json
179192
180193
\b
181-
Scan 'mydir' directory for licenses and copyrights. Save scan results to an
182-
HTML app file for interactive web browser results navigation. Additional app
194+
Scan the 'samples' directory for licenses and copyrights. Save scan results to
195+
an HTML app file for interactive web browser results navigation. Additional app
183196
files are saved to the 'myscan_files' directory:
184197
185-
scancode --format html-app mydir myscan.html
198+
scancode --format html-app samples myscan.html
199+
200+
Note: when you run scancode, a progress bar is displayed with a counter of the
201+
number of files processed. Use --verbose to display file-by-file progress.
186202
'''
187203

188204

189205
short_help = '''Usage: scancode [OPTIONS] <input> <output_file>
190-
Try 'scancode --help' for more information.'''
206+
Try 'scancode --help' for help on options and arguments.'''
191207

192208

193209
formats = ['json', 'html', 'html-app']
@@ -209,16 +225,16 @@ def get_usage(self, ctx):
209225
@click.option('-l', '--license', is_flag=True, default=False, help='Scan <input> for licenses. [default]')
210226
@click.option('-f', '--format', metavar='<style>', type=click.Choice(formats),
211227
default='json', show_default=True,
212-
help='Set format <style> to one of: %s' % '|'.join(formats),
228+
help='Set <output_file> format <style> to one of: %s' % ' or '.join(formats),
213229
)
214230
@click.option('-e', '--extract', is_flag=True, default=False, is_eager=True,
215-
help=('Extract archives found in <input> recursively, ignoring other options.'))
231+
help=('Extract archives found in <input>, ignoring other scan options.'))
232+
@click.option('--verbose', is_flag=True, default=False, help='Print verbose file-by-file progress messages.')
216233
@click.help_option('-h', '--help')
217234
@click.option('--examples', is_flag=True, is_eager=True, callback=print_examples,
218235
help=('Show command examples and exit.'))
219236
@click.option('--about', is_flag=True, is_eager=True, callback=print_about,
220-
help=('Show ScanCode and licensing information and exit.'))
221-
@click.option('--verbose', is_flag=True, default=False, help='Show verbose scan progress messages.')
237+
help=('Show information about ScanCode and licensing and exit.'))
222238
@click.option('--version', is_flag=True, is_eager=True, callback=print_version,
223239
help=('Show the version and exit.'))
224240
def scancode(ctx, input, output_file, extract, copyright, license, format, verbose, *args, **kwargs):
@@ -232,7 +248,8 @@ def scancode(ctx, input, output_file, extract, copyright, license, format, verbo
232248
# exclusive, ignoring other options.
233249
# FIXME: this should turned into a sub-command
234250
ctx.fail('''The '--extract' option cannot be combined with other scanning options.
235-
Use '--extract' alone to extract <input>, then run a scan on the extracted files.''')
251+
Use the '--extract' option alone to extract archives found in <input>.
252+
then run scancode again to scan the extracted files.''')
236253
ctx.exit(1)
237254

238255
click.secho('Extracting archives...', fg='green')
@@ -266,7 +283,8 @@ def scancode(ctx, input, output_file, extract, copyright, license, format, verbo
266283
try:
267284
create_html_app_assets(output_file)
268285
except HtmlAppAssetCopyWarning:
269-
click.secho('\nHTML app creation skipped when printing to terminal.', fg='yellow')
286+
click.secho('\nHTML app creation skipped when printing to terminal.',
287+
fg='yellow')
270288
except HtmlAppAssetCopyError:
271289
click.secho('\nFailed to create HTML app.', fg='red')
272290

@@ -308,7 +326,17 @@ def extract_with_progress(input, verbose=False):
308326
"""
309327
Extract archives and display progress.
310328
"""
311-
if not verbose:
329+
if verbose:
330+
for xev in extract_archives(input, verbose=verbose):
331+
if not xev.done:
332+
click.secho('Extracting: ' + xev.source + ': ', nl=False, fg='green')
333+
else:
334+
if xev.warnings or xev.errors:
335+
click.secho('done.', fg='red' if xev.errors else 'yellow')
336+
display_extract_event(xev)
337+
else:
338+
click.secho('done.', fg='green')
339+
else:
312340
extract_results = []
313341
# only display a progress bar
314342
with click.progressbar(extract_archives(input, verbose=verbose), show_pos=True) as extractions:
@@ -317,18 +345,10 @@ def extract_with_progress(input, verbose=False):
317345
# display warnings/errors at the end
318346
for xev in extract_results:
319347
if xev.warnings or xev.errors:
320-
click.secho('Extraction errors or warnings for: ' + xev.source, fg='yellow')
321-
display_extract_event(xev)
322-
else:
323-
for xev in extract_archives(input, verbose=verbose):
324-
if not xev.done:
325-
click.secho('Extracting: ' + xev.source + ': ', nl=False, fg='green')
326-
else:
327348
if xev.warnings or xev.errors:
349+
click.secho('Extracting: ' + xev.source + ': ', nl=False, fg='green')
328350
click.secho('done.', fg='red' if xev.errors else 'yellow')
329351
display_extract_event(xev)
330-
else:
331-
click.secho('done.', fg='green')
332352

333353

334354
def display_extract_event(xev):

0 commit comments

Comments
 (0)