コード例 #1
0
def main(args=None):
    """Either takes arguments or gets them from sys.argv. Calls the bragly.cli
        parsing function parse_args, and then executes the returned function.
        See the usage at the command line by passing --help as an option.
    Args:
        args (list): A list of arguments that would be in sys.argv. If None,
            args will be populated from sys.argv.

    Returns:
        int:
            0 - If the program runs without exception.
            1 - If the program runs but there is an unexpected exception
            2 - If the program runs and no arguments are parsed form the command
                line.
    """
    if args is None:
        args = sys.argv[1:]
    parser, args = parse_args(args)
    if not args:
        parser.print_help()
        return 2

    func = args.pop('func', None)
    if func is None:
        print("Operation failed for unexpected reason")
        return 1
    results = func(**args)
    for result in results:
        print(result)
    return 0
コード例 #2
0
ファイル: __main__.py プロジェクト: huntcsg/bragly
def main(args=None):
    """Either takes arguments or gets them from sys.argv. Calls the bragly.cli
        parsing function parse_args, and then executes the returned function.
        See the usage at the command line by passing --help as an option.
    Args:
        args (list): A list of arguments that would be in sys.argv. If None,
            args will be populated from sys.argv.

    Returns:
        int:
            0 - If the program runs without exception.
            1 - If the program runs but there is an unexpected exception
            2 - If the program runs and no arguments are parsed form the command
                line.
    """
    if args is None:
        args = sys.argv[1:]
    parser, args = parse_args(args)
    if not args:
        parser.print_help()
        return 2

    func = args.pop('func', None)
    if func is None:
        print("Operation failed for unexpected reason")
        return 1
    results = func(**args)
    for result in results:
        print(result)
    return 0
コード例 #3
0
def check_read_parsing(args, result):
    args = args.split()
    parser, args = parse_args(args)
    comp_keys = ['start', 'end', 'period', 'form']
    for key in comp_keys:
        if key in result:
            assert (args[key] == result[key])
        else:
            assert (args[key] is None)

    assert (args['func'].__name__ == result['func'])
コード例 #4
0
def check_write_parsing(args, result):
    args = args.split()
    parser, args = parse_args(args)
    comp_keys = ['message', 'timestamp', 'tags']
    for key in comp_keys:
        if key in result:
            assert (args[key] == result[key])
        else:
            assert (args[key] is None)

    assert (args['func'].__name__ == result['func'])
コード例 #5
0
ファイル: test_cli.py プロジェクト: huntcsg/bragly
def check_search_parsing(args, result):
    args = args.split()
    parser, args = parse_args(args)
    comp_keys = ['start', 'end', 'period', 'form']
    for key in comp_keys:
        if key in result:
            assert (args[key] == result[key])
        else:
            assert (args[key] is None)

    assert (args['func'].__name__ == result['func'])
コード例 #6
0
ファイル: test_cli.py プロジェクト: huntcsg/bragly
def check_write_parsing(args, result):
    args = args.split()
    parser, args = parse_args(args)
    comp_keys = ['message', 'timestamp', 'tags']
    for key in comp_keys:
        if key in result:
            assert (args[key] == result[key])
        else:
            assert (args[key] is None)

    assert (args['func'].__name__ == result['func'])
コード例 #7
0
def check_args(args, result_keys):
    args = args.split()

    parser, args = parse_args(args)

    assert (set(result_keys) == set(args.keys()))
コード例 #8
0
ファイル: test_cli.py プロジェクト: huntcsg/bragly
def check_args(args, result_keys):
    args = args.split()

    parser, args = parse_args(args)

    assert (set(result_keys) == set(args.keys()))