From b09f3b0af2167e2da39a66344b3c1750b14c4355 Mon Sep 17 00:00:00 2001 From: pombredanne Date: Mon, 7 Dec 2015 13:44:09 +0100 Subject: [PATCH] Revert "Added --package scan option for #44, removed --extract option for #52" This reverts commit 47329fc103f477d375bdb705e04e25ef14306afd. --- src/scancode/cli.py | 286 +++++++++++++++++------------- tests/scancode/test_cli.py | 350 ++++++++++++++++++++----------------- 2 files changed, 357 insertions(+), 279 deletions(-) diff --git a/src/scancode/cli.py b/src/scancode/cli.py index fffc882d289..ede8d89844b 100644 --- a/src/scancode/cli.py +++ b/src/scancode/cli.py @@ -28,28 +28,22 @@ from functools import partial import json import os -from types import GeneratorType import click -from click.termui import style -from commoncode import ignore +from commoncode import ignore, fileutils from commoncode.fileutils import resource_iter -from commoncode import fileutils from scancode import __version__ as version -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 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.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 = ''' @@ -162,7 +156,20 @@ def print_about(ctx, param, value): scancode -f json -l -c samples/zlib/ > scan.json -To extract archives, see the 'extractcode' command instead. +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 ''' @@ -200,146 +207,179 @@ def print_version(ctx, param, value): ''' -class ScanCommand(utils.BaseCommand): - short_usage_help = ''' +short_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('-p', '--package', is_flag=True, default=False, help='Scan for packages. [default]') -@click.option('-i', '--info', is_flag=True, default=False, help='Scan for files information.') - -@click.option('-f', '--format', is_flag=False, default='json', show_default=True, metavar='