88from .model .user_input import UserInput
99from .model .user_input_exception import UserInputException
1010from .modules .admin_operations import AdminOperations
11+ from .modules .user_operations import UserOperations
1112
1213def main ():
14+ #
15+ # INIT
16+ #
1317 colorama .init (autoreset = True )
1418 printHelper = PrintHelper ()
15-
1619 print (colorama .Fore .CYAN + '\n ~~ REST API Client for Customfield Editor Plugin ~~ v1.2rc1' )
1720
21+ #
22+ # CLI PARAMS
23+ #
1824 parser = argparse .ArgumentParser (description = 'Customfield Editor Plugin REST API CLI Client.' )
1925 parser .add_argument ("-cid" , "--customFieldId" , type = int , help = 'The ID of the custom field.' )
2026 parser .add_argument ("-ulist" , "--userList" , nargs = '+' , help = 'space separated user names to grant permission' )
2127 parser .add_argument ("-glist" , "--groupList" , nargs = '+' , help = 'space separated group names to grant permission' )
22- parser .add_argument ("-a" , "--action" , help = 'Which action to execute.' , choices = ['adminListFields' , 'adminGrantPermission' ], required = True )
28+ parser .add_argument ("-a" , "--action" , help = 'Which action to execute.' , choices = ['adminListFields' , 'adminGrantPermission' , 'userListFields' ], required = True )
2329 parser .add_argument ("-url" , "--baseUrl" , help = 'baseUrl to JIRA instance e.g. http://server:port/jira/' , required = True )
2430 parser .add_argument ("-user" , "--authUsername" , help = 'username for basic auth.' , required = True )
2531 parser .add_argument ("-pass" , "--authPassword" , help = 'password for basic auth.' , required = True )
2632 args = parser .parse_args ()
2733
2834
35+ #
36+ # INITIALIZE HELPERS
37+ #
2938 printHelper .step ('initializing' )
3039 try :
3140 userInput = UserInput (args .baseUrl , args .authUsername , args .authPassword )
@@ -34,9 +43,6 @@ def main():
3443 print (ex )
3544 sys .exit (1 )
3645 printHelper .success ('UserInput is valid.' )
37-
38-
39-
4046 try :
4147 apiHelper = ApiHelper (userInput )
4248 except ApiHelperException as ex :
@@ -46,12 +52,25 @@ def main():
4652 printHelper .success ('ApiHelper initialized.' )
4753
4854
55+ #
56+ # INITIALIZE OPERATIONS
57+ #
4958 adminOperations = AdminOperations (apiHelper )
59+ userOperations = UserOperations (apiHelper )
60+
5061
62+ #
63+ # EXECUTE ACTIONS
64+ #
5165 try :
66+ printHelper .action (args .action )
5267
68+ #
69+ # ADMIN ACTIONS
70+ #
5371 # $> cep-client -a adminListFields -url http://localhost:2990/jira/ -user admin -pass admin
5472 if args .action == 'adminListFields' :
73+
5574 adminOperations .list_fields ()
5675
5776 #> cep-client -a adminGrantPermission --customFieldId 10100 --userList bob steve -url http://localhost:2990/jira -user admin -pass admin
@@ -60,6 +79,14 @@ def main():
6079 adminOperations .grant_permission (args .customFieldId , args .userList , args .groupList )
6180
6281
82+ #
83+ # USER ACTIONS
84+ #
85+ if args .action == 'userListFields' :
86+ userOperations .list_fields ()
87+
88+
89+
6390 except requests .ConnectionError as ex :
6491 print ('' )
6592 printHelper .error ('There seemed to a be problem with your request. Check errors above. EXIT' )
@@ -70,6 +97,8 @@ def main():
7097 printHelper .error ('There seemed to a be problem with your request. Check errors above. EXIT' )
7198 sys .exit (1 )
7299
73-
100+ #
101+ # EXIT SUCCESS
102+ #
74103 print ('\n ' )
75104 printHelper .success ('EXIT gracefully' )
0 commit comments