예제 #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()))