@@ -82,23 +82,30 @@ def get_existing_type(response):
82
82
return response .get .kvs [0 ].value .WhichOneof ("value" ).replace ("val" , "" )
83
83
84
84
85
- def format_kvs (kvs ):
85
+ def format_kvs (kvs , verbose = False ):
86
86
kvstrings = []
87
87
for kv in kvs :
88
88
if kv .value :
89
89
key_type = kv .value .WhichOneof ("value" ).replace ("val" , "" )
90
90
value = UnpackFromProto (kv .value )
91
91
if isinstance (value , str ) or isinstance (value , unicode ):
92
92
value = "\" %s\" " % value
93
- kvstrings .append ("%s = %s, type = %s" % (kv .key , value , key_type ))
93
+
94
+ output_str = (
95
+ "%s = %s, type = %s" % (kv .key , value , key_type )
96
+ if verbose
97
+ else "%s = %s" % (kv .key , value ))
98
+ kvstrings .append (output_str )
94
99
return "\n " .join (sorted (kvstrings ))
95
100
96
101
97
- def format_set_output (response ):
102
+ def format_set_output (response , verbose = False ):
98
103
if response .status == sysadminctl_pb2 .SUCCESS_KEY_CREATED :
99
- return "Uncommitted created new entry\n " + format_kvs (response .get .kvs )
104
+ return "Uncommitted created new entry\n " + format_kvs (response .get .kvs ,
105
+ verbose )
100
106
elif response .status == sysadminctl_pb2 .SUCCESS :
101
- return "Uncommitted modified entry\n " + format_kvs (response .get .kvs )
107
+ return "Uncommitted modified entry\n " + format_kvs (response .get .kvs ,
108
+ verbose )
102
109
return response
103
110
104
111
@@ -112,6 +119,8 @@ class SetCommand(object):
112
119
self .parser .add_argument ("--type" , type = str , default = "str" ,
113
120
choices = type_choices ,
114
121
help = "value type, default: str" )
122
+ self .parser .add_argument ("-v" , "--verbose" , action = 'store_true' ,
123
+ help = "Enable verbose output" )
115
124
116
125
def run (self , args ):
117
126
client = SysAdminClient (args .host , args .port , args .xid )
@@ -127,7 +136,7 @@ class SetCommand(object):
127
136
pyvalue = convertToType (args .value , new_type )
128
137
except ValueError as err :
129
138
return err
130
- return format_set_output (client .set (args .key , pyvalue ))
139
+ return format_set_output (client .set (args .key , pyvalue ), args . verbose )
131
140
132
141
133
142
class ModifyCommand (object ):
@@ -148,6 +157,8 @@ class ModifyCommand(object):
148
157
self .parser .add_argument ("--type" , type = str ,
149
158
choices = type_choices ,
150
159
help = "value type" )
160
+ self .parser .add_argument ("-v" , "--verbose" , action = 'store_true' ,
161
+ help = "Enable verbose output" )
151
162
152
163
def run (self , args ):
153
164
client = SysAdminClient (args .host , args .port , args .xid )
@@ -164,12 +175,14 @@ class ModifyCommand(object):
164
175
pyvalue = convertToType (args .value , existing_type )
165
176
except ValueError as err :
166
177
return err
167
- return format_set_output (client .set (args .key , pyvalue ))
178
+ return format_set_output (
179
+ client .set (args .key , pyvalue ),
180
+ args .verbose )
168
181
169
182
170
- def format_get_output (key , response ):
183
+ def format_get_output (key , response , verbose = False ):
171
184
if response .status == sysadminctl_pb2 .SUCCESS :
172
- return format_kvs (response .get .kvs )
185
+ return format_kvs (response .get .kvs , verbose )
173
186
elif response .status == sysadminctl_pb2 .KEY_NOT_FOUND :
174
187
return "Key not found: " + key
175
188
else :
@@ -181,10 +194,12 @@ class GetCommand(object):
181
194
self .parser = argparser .add_parser ("get" )
182
195
self .parser .add_argument ("key" , type = str ,
183
196
help = "key" )
197
+ self .parser .add_argument ("-v" , "--verbose" , action = 'store_true' ,
198
+ help = "get output with variable type" )
184
199
185
200
def run (self , args ):
186
201
client = SysAdminClient (args .host , args .port , args .xid )
187
- return format_get_output (args .key , client .get (args .key ))
202
+ return format_get_output (args .key , client .get (args .key ), args . verbose )
188
203
189
204
190
205
def format_commit_output (response ):
0 commit comments