diff --git a/src/scancode/cli.py b/src/scancode/cli.py index ede8d89844b..fffc882d289 100644 --- a/src/scancode/cli.py +++ b/src/scancode/cli.py @@ -28,22 +28,28 @@ from functools import partial import json import os +from types import GeneratorType import click +from click.termui import style -from commoncode import ignore, fileutils +from commoncode import ignore from commoncode.fileutils import resource_iter +from commoncode import fileutils from scancode import __version__ as version -from scancode.api import as_html -from scancode.api import as_html_app -from scancode.api import create_html_app_assets -from scancode.api import extract_archives +from scancode import utils + +from scancode.format import as_html +from scancode.format import as_html_app +from scancode.format import create_html_app_assets +from scancode.format import HtmlAppAssetCopyWarning +from scancode.format import HtmlAppAssetCopyError + from scancode.api import get_copyrights from scancode.api import get_licenses -from scancode.api import HtmlAppAssetCopyWarning -from scancode.api import HtmlAppAssetCopyError from scancode.api import get_file_infos +from scancode.api import get_package_infos info_text = ''' @@ -156,20 +162,7 @@ def print_about(ctx, param, value): scancode -f json -l -c samples/zlib/ > scan.json -Extract all archives found in the 'samples' directory tree: - - scancode --extract samples - -Note: If an archive contains other archives, all contained archives will be -extracted recursively. Extraction is done directly in the 'samples' directory, -side-by-side with each archive. Files are extracted in a directory named after -the archive with an '-extract' suffix added to its name, created side-by-side -with the corresponding archive file. - -Extract a single archive. Files are extracted in the directory -'samples/arch/zlib.tar.gz-extract/': - - scancode --extract samples/arch/zlib.tar.gz +To extract archives, see the 'extractcode' command instead. ''' @@ -207,179 +200,146 @@ def print_version(ctx, param, value): ''' -short_help = ''' +class ScanCommand(utils.BaseCommand): + short_usage_help = ''' Try 'scancode --help' for help on options and arguments.''' formats = ['json', 'html', 'html-app'] -class ScanCommand(click.Command): - def get_usage(self, ctx): - """ - Ensure that usage points to the --help option explicitly. - Workaround click issue https://github.com/mitsuhiko/click/issues/393 - """ - return click.Command.get_usage(self, ctx) + short_help - - def main(self, args=None, prog_name=None, complete_var=None, - standalone_mode=True, **extra): - """ - Workaround click 4.0 bug https://github.com/mitsuhiko/click/issues/365 - """ - return click.Command.main(self, args=args, prog_name=self.name, - complete_var=complete_var, - standalone_mode=standalone_mode, **extra) - - @click.command(name='scancode', epilog=epilog_text, cls=ScanCommand) @click.pass_context + @click.argument('input', metavar='', type=click.Path(exists=True, readable=True)) @click.argument('output_file', default='-', metavar='', type=click.File('wb')) + @click.option('-c', '--copyright', is_flag=True, default=False, help='Scan for copyrights. [default]') @click.option('-l', '--license', is_flag=True, default=False, help='Scan for licenses. [default]') -@click.option('-i', '--info', is_flag=True, default=False, help='Collect files information from .') -@click.option('-f', '--format', metavar='