@cli.group(invoke_without_command=True)
@click.option(
    '-a',
    '--attributes',
    metavar='ATTRS',
    help='A key/value pair attached to this Network (format: key=value).',
    multiple=True,
)
@click.option(
    '-c',
    '--cidr',
    metavar='CIDR',
    help=(
        'Filter to Networks matching this CIDR. If provided, this overrides '
        '-n/--network-address and -p/--prefix-length.'
    ),
)
@click.option(
    '-d',
    '--delimited',
    is_flag=True,
    help='Display set query results separated by commas vs. newlines.',
    default=False,
    show_default=True,
)
@click.option(
    '-g',
    '--grep',
    is_flag=True,
    help='Display list results in a grep-friendly format.',
    default=False,
    show_default=True,
)
@click.option(
    '-i',
    '--id',
    metavar='ID',
    type=int,
    help='Unique ID of the Network being retrieved.',
)
@click.option(
    '--include-networks/--no-include-networks',
    is_flag=True,
    help='Include/exclude non-IP networks.',
    default=True,
    show_default=True,
)
@click.option(
    '--include-ips/--no-include-ips',
    is_flag=True,
    help='Include/exclude IP addresses.',
    default=True,
    show_default=True,
)
@click.option(
    '-V',
    '--ip-version',
    metavar='IP_VERSION',
    type=click.Choice(['4', '6']),
    help='Filter to Networks matchin this IP version.',
)
@click.option(
    '-l',
    '--limit',
    metavar='LIMIT',
    help='Limit result to N resources.',
)
@click.option(
    '-n',
    '--network-address',
    metavar='NETWORK',
    help='Filter to Networks matching this network address.',
)
@click.option(
    '-N',
    '--natural-key',
    is_flag=True,
    help='Display list results by their natural key',
    default=False,
    show_default=True,
)
@click.option(
    '-o',
    '--offset',
    metavar='OFFSET',
    help='Skip the first N resources.',
)
@click.option(
    '-p',
    '--prefix-length',
    metavar='PREFIX',
    type=int,
    help='Filter to Networks matching this prefix length.',
)
@click.option(
    '-q',
    '--query',
    metavar='QUERY',
    help='Perform a set query using Attributes and output matching Networks.',
)
@click.option(
    '-r',
    '--root-only',
    is_flag=True,
    help='Filter to root Networks.',
    default=False,
    show_default=True,
)
@click.option(
    '-S',
    '--state',
    metavar='STATE',
    type=str,
    help='The allocation state of the Network.',
)
@click.option(
    '-s',
    '--site-id',
    metavar='SITE_ID',
    help='Unique ID of the Site this Network is under.  [required]',
    callback=callbacks.process_site_id,
)
@click.pass_context
def list(ctx, attributes, cidr, delimited, grep, id, include_ips,
         include_networks, ip_version, limit, network_address, natural_key,
         offset, prefix_length, query, root_only, state, site_id):
    """
    List existing Networks for a Site.

    You must provide a Site ID using the -s/--site-id option.

    When listing Networks, all objects are displayed by default. You optionally
    may lookup a single Network by ID using the -i/--id option.

    You may limit the number of results using the -l/--limit option.
    """
    data = ctx.params
    data.pop('delimited')  # We don't want this going to the server.

    # If we aren't passing a sub-command, just call list(), otherwise let it
    # fallback to default behavior.
    if ctx.invoked_subcommand is None:
        if query is not None:
            results = ctx.obj.set_query(data)
            networks = get_result(results)
            networks = sorted(
                (d['network_address'], d['prefix_length']) for d in networks
            )
            networks = ['%s/%s' % obj for obj in networks]
            joiner = ',' if delimited else '\n'
            click.echo(joiner.join(networks))
        else:
            ctx.obj.list(data, display_fields=DISPLAY_FIELDS)
dataset/ETHPy150Open dropbox/pynsot/pynsot/commands/cmd_networks.py/list/original