@@ -16,28 +16,55 @@ def main():
1616 #
1717 colorama .init (autoreset = True )
1818 printHelper = PrintHelper ()
19- print (colorama .Fore .CYAN + '\n ~~ REST API Client for Customfield Editor Plugin ~~ v1.2rc1' )
19+ print (colorama .Fore .CYAN + '\n ~~ REST API Client for Customfield Editor Plugin ~~ v1.2rc1\n ' )
2020
2121 #
2222 # CLI PARAMS
2323 #
2424 parser = argparse .ArgumentParser (description = 'Customfield Editor Plugin REST API CLI Client.' )
25+
26+ parser .add_argument ("-a" , "--action" , help = 'Which action to execute.' , choices = ['adminListFields' , 'adminGrantPermission' , 'userListFields' , 'userListOptions' ])
27+ parser .add_argument ("-url" , "--baseUrl" , help = 'baseUrl to JIRA instance e.g. http://server:port/jira/' )
28+ parser .add_argument ("-user" , "--authUsername" , help = 'username for basic auth.' )
29+ parser .add_argument ("-pass" , "--authPassword" , help = 'password for basic auth.' )
30+
31+ #
32+ # CLI PARAMS depending on action
33+ #
2534 parser .add_argument ("-cid" , "--customFieldId" , type = int , help = 'The ID of the custom field.' )
35+ parser .add_argument ("-ctx" , "--contextId" , type = int , help = 'The ID of the custom field context.' )
2636 parser .add_argument ("-ulist" , "--userList" , nargs = '+' , help = 'space separated user names to grant permission' )
2737 parser .add_argument ("-glist" , "--groupList" , nargs = '+' , help = 'space separated group names to grant permission' )
28- parser .add_argument ("-a" , "--action" , help = 'Which action to execute.' , choices = ['adminListFields' , 'adminGrantPermission' , 'userListFields' ], required = True )
29- parser .add_argument ("-url" , "--baseUrl" , help = 'baseUrl to JIRA instance e.g. http://server:port/jira/' , required = True )
30- parser .add_argument ("-user" , "--authUsername" , help = 'username for basic auth.' , required = True )
31- parser .add_argument ("-pass" , "--authPassword" , help = 'password for basic auth.' , required = True )
38+
3239 args = parser .parse_args ()
40+ if not args .action :
41+ printHelper .headline ('USAGE' )
42+ printHelper .step ('admin operations' )
43+ print (' list fields:' )
44+ print (' $> cep-client -a adminListFields -url http://localhost:2990/jira/ -user admin -pass admin' )
45+ print ('' )
46+ print (' grant permissions:' )
47+ print (' $> cep-client -a adminGrantPermission --customFieldId 10100 --userList bob steve \ \n '
48+ ' -url http://localhost:2990/jira/ -user admin -pass admin' )
49+ print (' OPTIONAL: --groupList with one or more groupnames' )
50+
51+ printHelper .step ('user operations' )
52+ print (' list fields:' )
53+ print (' $> cep-client -a userListFields -url http://localhost:2990/jira/ -user admin -pass admin' )
54+ print ('' )
55+ print (' list options:' )
56+ print (' $> cep-client -a userListOptions --customFieldId 10001 -url http://localhost:2990/jira/ -user admin -pass admin' )
57+ # $> cep-client -a adminGrantPermission --customFieldId 10100 --userList bob steve -url http://localhost:2990/jira -user admin -pass admin
58+ # (optional: --groupList)
59+ sys .exit (1 )
3360
3461
3562 #
3663 # INITIALIZE HELPERS
3764 #
3865 printHelper .step ('initializing' )
3966 try :
40- userInput = UserInput (args . baseUrl , args . authUsername , args . authPassword )
67+ userInput = UserInput (args )
4168 except UserInputException as ex :
4269 printHelper .error ('UserInput is invalid.' )
4370 print (ex )
@@ -68,13 +95,11 @@ def main():
6895 #
6996 # ADMIN ACTIONS
7097 #
71- # $> cep-client -a adminListFields -url http://localhost:2990/jira/ -user admin -pass admin
98+ #
7299 if args .action == 'adminListFields' :
73-
74100 adminOperations .list_fields ()
75101
76- #> cep-client -a adminGrantPermission --customFieldId 10100 --userList bob steve -url http://localhost:2990/jira -user admin -pass admin
77- # (optional: --groupList)
102+
78103 if args .action == 'adminGrantPermission' :
79104 adminOperations .grant_permission (args .customFieldId , args .userList , args .groupList )
80105
@@ -85,6 +110,8 @@ def main():
85110 if args .action == 'userListFields' :
86111 userOperations .list_fields ()
87112
113+ if args .action == 'userListOptions' :
114+ userOperations .list_options (args .customFieldId , args .contextId )
88115
89116
90117 except requests .ConnectionError as ex :
0 commit comments