22# :license: MIT, see LICENSE for more details.
33
44import click
5+ import json
56
67import SoftLayer
7- from SoftLayer .CLI import columns as column_helper
88from SoftLayer .CLI import environment
9- from SoftLayer .CLI import formatting
10-
11-
12- COLUMNS = [
13- column_helper .Column ('id' , ('id' ,)),
14- column_helper .Column ('username' , ('username' ,)),
15- column_helper .Column ('email' , ('email' ,)),
16- column_helper .Column ('displayName' , ('displayName' ,)),
17- column_helper .Column ('status' , ('userStatus' , 'name' )),
18- column_helper .Column ('hardwareCount' , ('hardwareCount' ,)),
19- column_helper .Column ('virtualGuestCount' , ('virtualGuestCount' ,))
20- ]
21-
22- DEFAULT_COLUMNS = [
23- 'id' ,
24- 'username' ,
25- 'email' ,
26- 'displayName'
27- ]
9+ from SoftLayer .CLI import helpers
2810
2911
3012@click .command ()
31- @click .option ('--columns' ,
32- callback = column_helper .get_formatter (COLUMNS ),
33- help = 'Columns to display. [options: %s]' % ', ' .join (column .name for column in COLUMNS ),
34- default = ',' .join (DEFAULT_COLUMNS ),
35- show_default = True )
13+ @click .argument ('user' )
14+ @click .option ('--template' , '-t' , required = True ,
15+ help = "A json string describing https://softlayer.github.io/reference/datatypes/SoftLayer_User_Customer/" )
3616@environment .pass_env
37- def cli (env , columns ):
38- """List Users."""
17+ def cli (env , user , template ):
18+ """Edit a Users details
3919
40- mgr = SoftLayer .UserManager (env .client )
41- users = mgr .list_users ()
42-
43- table = formatting .Table (columns .columns )
44- for user in users :
45- table .add_row ([value or formatting .blank ()
46- for value in columns .row (user )])
20+ JSON strings should be enclosed in '' and each item should be enclosed in ""
4721
48- env .fout (table )
22+ :Example: slcli user edit-details testUser -t '{"firstName": "Test", "lastName": "Testerson"}'
23+ ."""
24+ mgr = SoftLayer .UserManager (env .client )
25+ user_id = helpers .resolve_id (mgr .resolve_ids , user , 'username' )
26+
27+ user_template = {}
28+ if template is not None :
29+ try :
30+ template_object = json .loads (template )
31+ for key in template_object :
32+ user_template [key ] = template_object [key ]
33+ except json .decoder .JSONDecodeError as ex :
34+ raise exceptions .ArgumentError ("Unable to parse --template. %s" % ex .msg )
35+
36+ result = mgr .edit_user (user_id , user_template )
37+ if result :
38+ click .secho ("%s updated successfully" % (user ), fg = 'green' )
39+ else :
40+ click .secho ("Failed to update %s" % (user ), fg = 'red' )
0 commit comments