def do_state(args):
    """Runs the batch list or batch show command, printing output to the
    console

        Args:
            args: The parsed arguments sent to the command at runtime
    """
    rest_client = RestClient(args.url, args.user)

    if args.subcommand == 'list':
        response = rest_client.list_state(args.subtree, args.head)
        leaves = response['data']
        head = response['head']
        keys = ('address', 'size', 'data')
        headers = tuple(k.upper() for k in keys)

        def parse_leaf_row(leaf, decode=True):
            decoded = b64decode(leaf['data'])
            return (
                leaf['address'],
                len(decoded),
                str(decoded) if decode else leaf['data'])

        if args.format == 'default':
            fmt.print_terminal_table(headers, leaves, parse_leaf_row)
            print('HEAD BLOCK: "{}"'.format(head))

        elif args.format == 'csv':
            fmt.print_csv(headers, leaves, parse_leaf_row)
            print('(data for head block: "{}")'.format(head))

        elif args.format == 'json' or args.format == 'yaml':
            state_data = {
                'head': head,
                'data': [{k: d for k, d in zip(keys, parse_leaf_row(l, False))}
                         for l in leaves]}

            if args.format == 'yaml':
                fmt.print_yaml(state_data)
            elif args.format == 'json':
                fmt.print_json(state_data)
            else:
                raise AssertionError('Missing handler: {}'.format(args.format))

        else:
            raise AssertionError('Missing handler: {}'.format(args.format))

    if args.subcommand == 'show':
        output = rest_client.get_leaf(args.address, args.head)
        if output is not None:
            print('DATA: "{}"'.format(b64decode(output['data'])))
            print('HEAD: "{}"'.format(output['head']))
        else:
            raise CliException('No data available at {}'.format(args.address))
def do_state ( args ) : rest_client = RestClient ( args . url , args . user ) if args . subcommand == 'list' : response = rest_client . list_state ( args . subtree , args . head ) leaves = response [ 'data' ] head = response [ 'head' ] keys = ( 'address' , 'size' , 'data' ) headers = tuple ( k . upper ( ) for k in keys ) def parse_leaf_row ( leaf , decode = True ) : decoded = b64decode ( leaf [ 'data' ] ) return ( leaf [ 'address' ] , len ( decoded ) , str ( decoded ) if decode else leaf [ 'data' ] ) if args . format == 'default' : fmt . print_terminal_table ( headers , leaves , parse_leaf_row ) print ( 'HEAD BLOCK: "{}"' . format ( head ) ) elif args . format == 'csv' : fmt . print_csv ( headers , leaves , parse_leaf_row ) print ( '(data for head block: "{}")' . format ( head ) ) elif args . format == 'json' or args . format == 'yaml' : state_data = { 'head' : head , 'data' : [ { k : d for k , d in zip ( keys , parse_leaf_row ( l , False ) ) } for l in leaves ] } if args . format == 'yaml' : fmt . print_yaml ( state_data ) elif args . format == 'json' : fmt . print_json ( state_data ) else : raise AssertionError ( 'Missing handler: {}' . format ( args . format ) ) else : raise AssertionError ( 'Missing handler: {}' . format ( args . format ) ) if args . subcommand == 'show' : output = rest_client . get_leaf ( args . address , args . head ) if output is not None : print ( 'DATA: "{}"' . format ( b64decode ( output [ 'data' ] ) ) ) print ( 'HEAD: "{}"' . format ( output [ 'head' ] ) ) else : raise CliException ( 'No data available at {}' . format ( args . address ) )
Runs the batch list or batch show command, printing output to the
    console

        Args:
            args: The parsed arguments sent to the command at runtime