1313
1414
1515@click .command ()
16- @click .argument ('location' , required = False , nargs = - 1 , type = click .UNPROCESSED )
1716@click .argument ('package_keyname' )
18- @click .option ('--keyword' , help = "A word (or string) used to filter item names." )
19- @click .option ('--category' , help = "Category code to filter items by" )
17+ @click .option ('--keyword' , '-k' , help = "A word (or string) used to filter item names." )
18+ @click .option ('--category' , '-c' , help = "Category code to filter items by" )
2019@click .option ('--prices' , '-p' , is_flag = True , help = 'Use --prices to list the server item prices, and to list the '
2120 'Item Prices by location, add it to the --prices option using '
2221 'location KeyName, e.g. --prices AMSTERDAM02' )
22+ @click .argument ('location' , required = False )
2323@environment .pass_env
24- def cli (env , location , package_keyname , keyword , category , prices ):
24+ def cli (env , package_keyname , keyword , category , prices , location = None ):
2525 """List package items used for ordering.
2626
2727 The item keyNames listed can be used with `slcli order place` to specify
@@ -57,14 +57,13 @@ def cli(env, location, package_keyname, keyword, category, prices):
5757 if prices :
5858 _item_list_prices (categories , sorted_items , tables )
5959 if location :
60- location = location [0 ]
6160 location_prices = manager .get_item_prices_by_location (location , package_keyname )
6261 _location_item_prices (location_prices , location , tables )
6362 else :
6463 table_items_detail = formatting .Table (COLUMNS )
65- for catname in sorted (categories ):
66- for item in sorted_items [catname ]:
67- table_items_detail .add_row ([catname , item ['keyName' ], item ['description' ], get_price (item )])
64+ for category_name in sorted (categories ):
65+ for item in sorted_items [category_name ]:
66+ table_items_detail .add_row ([category_name , item ['keyName' ], item ['description' ], get_price (item )])
6867 tables .append (table_items_detail )
6968 env .fout (formatting .listing (tables , separator = '\n ' ))
7069
@@ -94,13 +93,13 @@ def get_price(item):
9493def _item_list_prices (categories , sorted_items , tables ):
9594 """Add the item prices cost and capacity restriction to the table"""
9695 table_prices = formatting .Table (COLUMNS_ITEM_PRICES )
97- for catname in sorted (categories ):
98- for item in sorted_items [catname ]:
96+ for category in sorted (categories ):
97+ for item in sorted_items [category ]:
9998 for price in item ['prices' ]:
10099 if not price .get ('locationGroupId' ):
101- cr_max = _get_price_data (price , 'capacityRestrictionMaximum' )
102- cr_min = _get_price_data (price , 'capacityRestrictionMinimum' )
103- cr_type = _get_price_data (price , 'capacityRestrictionType' )
100+ cr_max = get_item_price_data (price , 'capacityRestrictionMaximum' )
101+ cr_min = get_item_price_data (price , 'capacityRestrictionMinimum' )
102+ cr_type = get_item_price_data (price , 'capacityRestrictionType' )
104103 table_prices .add_row ([item ['keyName' ], price ['id' ],
105104 get_item_price_data (price , 'hourlyRecurringFee' ),
106105 get_item_price_data (price , 'recurringFee' ),
@@ -117,33 +116,22 @@ def get_item_price_data(price, item_attribute):
117116
118117
119118def _location_item_prices (location_prices , location , tables ):
120- """Get a specific data from HS price .
119+ """Add a location prices table to tables .
121120
122- :param price: Hardware Server price.
123- :param string item: Hardware Server price data.
121+ :param list location_prices : Location prices.
122+ :param string location : Location.
123+ :param list tables: Table list to add location prices table.
124124 """
125125 location_prices_table = formatting .Table (COLUMNS_ITEM_PRICES_LOCATION , title = "Item Prices for %s" % location )
126126 location_prices_table .sortby = 'keyName'
127127 location_prices_table .align = 'l'
128128 for price in location_prices :
129- cr_max = _get_price_data (price , 'capacityRestrictionMaximum' )
130- cr_min = _get_price_data (price , 'capacityRestrictionMinimum' )
131- cr_type = _get_price_data (price , 'capacityRestrictionType' )
129+ cr_max = get_item_price_data (price , 'capacityRestrictionMaximum' )
130+ cr_min = get_item_price_data (price , 'capacityRestrictionMinimum' )
131+ cr_type = get_item_price_data (price , 'capacityRestrictionType' )
132132 location_prices_table .add_row (
133133 [price ['item' ]['keyName' ], price ['id' ],
134- _get_price_data (price , 'hourlyRecurringFee' ),
135- _get_price_data (price , 'recurringFee' ),
134+ get_item_price_data (price , 'hourlyRecurringFee' ),
135+ get_item_price_data (price , 'recurringFee' ),
136136 "%s - %s %s" % (cr_min , cr_max , cr_type )])
137137 tables .append (location_prices_table )
138-
139-
140- def _get_price_data (price , item ):
141- """Get a specific data from HS price.
142-
143- :param price: Hardware Server price.
144- :param string item: Hardware Server price data.
145- """
146- result = '-'
147- if item in price :
148- result = price [item ]
149- return result
0 commit comments