"""List package presets."""
# :license: MIT, see LICENSE for more details.

import click

from SoftLayer.CLI import environment
from SoftLayer.CLI import formatting
from SoftLayer.managers import ordering

COLUMNS = ['name',
           'keyName',
           'description', ]


@click.command()
@click.argument('package_keyname')
@click.option('--keyword',
              help="A word (or string) used to filter preset names.")
@environment.pass_env
def cli(env, package_keyname, keyword):
    """List package presets.

    .. Note::
        Presets are set CPU / RAM / Disk allotments. You still need to specify required items.
        Some packages do not have presets.

    ::

        # List the presets for Bare Metal servers
        slcli order preset-list BARE_METAL_SERVER

        # List the Bare Metal server presets that include a GPU
        slcli order preset-list BARE_METAL_SERVER --keyword gpu

    """
    table = formatting.Table(COLUMNS)
    manager = ordering.OrderingManager(env.client)

    _filter = {}
    if keyword:
        _filter = {'activePresets': {'name': {'operation': '*= %s' % keyword}}}
    presets = manager.list_presets(package_keyname, filter=_filter)

    for preset in presets:
        table.add_row([
            preset['name'],
            preset['keyName'],
            preset['description']
        ])
    env.fout(table)

@@ -1237,32 +1237,36 @@
 w(%5B%0A            
+str(
 preset%5B'name'%5D,%0A
@@ -1259,24 +1259,33 @@
 eset%5B'name'%5D
+).strip()
 ,%0A          
@@ -1278,32 +1278,36 @@
 (),%0A            
+str(
 preset%5B'keyName'
@@ -1307,16 +1307,25 @@
 eyName'%5D
+).strip()
 ,%0A      
@@ -1326,24 +1326,28 @@
             
+str(
 preset%5B'desc
@@ -1355,16 +1355,25 @@
 iption'%5D
+).strip()
 %0A       

fix the empty lines