33
44from marvelcli import utils
55from marvelcli .project import project_queries
6+ from marvelcli .workspace import workspace_queries
67
78@click .option ('-p' , '--project-pk' , type = str , help = 'Pk of the project you want to delete' )
89@click .option ('-a' , '--auth' , type = str , help = 'Auth your request' )
@@ -14,10 +15,13 @@ def delete_project(project_pk: str, auth: str):
1415 r , json_data = utils .make_request (auth , query , params )
1516
1617 if r .status_code == 200 :
17- if not json_data ['data' ]['deleteproject' ]['ok' ]:
18- click .echo ('\n ' + json_data ['data' ]['deleteproject' ]['error' ]['message' ] + '\n ' )
18+ if json_data ['data' ]['deleteProject' ] is None :
19+ click .echo ("\n Project '%s' has not been deleted for the following reason: %s\n " % (
20+ project_pk ,
21+ json_data ['errors' ][0 ]['message' ]
22+ ))
1923 else :
20- click .echo (' \n "%s" has been successfully deleted from your Marvel account\n ' % pk )
24+ click .echo (" \n '%s' has been successfully deleted from your Marvel account\n " % project_pk )
2125 else :
2226 click .echo ("\n Try 'marvelcli delete_project --help' to make sure you are not missing any args.\n " )
2327
@@ -32,7 +36,10 @@ def add_groups_to_project(project_pk: int, group_pk: list, auth: str):
3236 r , json_data = utils .make_request (auth , query , params )
3337
3438 if r .status_code != 200 :
35- click .echo ('\n ' + json_data ['data' ]['addTeamsToProject' ]['error' ]['message' ] + '\n ' )
39+ if not project_pk or not group_pk :
40+ click .echo ("\n Looks like you might be missing some args, add `--help` to your command to see the options.\n " )
41+ else :
42+ click .echo ('\n ' + json_data ['data' ]['addTeamsToProject' ]['error' ]['message' ] + '\n ' )
3643 else :
3744 data_success = json_data ['data' ]['addTeamsToProject' ]['succeeded' ]
3845 data_failed = json_data ['data' ]['addTeamsToProject' ]['failed' ]
@@ -41,12 +48,14 @@ def add_groups_to_project(project_pk: int, group_pk: list, auth: str):
4148 successful_groups = []
4249 for s in data_success :
4350 successful_groups .append (s .get ('pk' ))
44- click .echo ("\n The following groups were successfully added to project %s: %s " % (project_pk , successful_groups ))
51+ click .echo ("\n The following groups were successfully added to project %s: %s \n " % (project_pk , successful_groups ))
4552
4653 if data_failed :
4754 click .echo ('\n The following groups could not be added to project %s:' % (project_pk ))
4855 for f in data_failed :
49- click .echo ("%s - %s \n " % (f .get ('teamPk' ), f .get ('message' )))
56+ click .echo ("%s - %s" % (f .get ('teamPk' ), f .get ('message' )))
57+
58+ click .echo ("\n " )
5059
5160@click .option ('-p' , '--project-pk' , type = int , help = 'Pk of the project you want to remove groups from' )
5261@click .option ('-g' , '--group_pk' , type = int , multiple = True , help = 'Use this flag for each group you want removed from your project' )
@@ -59,7 +68,10 @@ def remove_groups_from_project(project_pk: int, group_pk: list, auth: str):
5968 r , json_data = utils .make_request (auth , query , params )
6069
6170 if r .status_code != 200 :
62- click .echo ('\n ' + json_data ['data' ]['removeTeamsFromProject' ]['error' ]['message' ] + '\n ' )
71+ if not project_pk or not group_pk :
72+ click .echo ("\n Looks like you might be missing some args, add `--help` to your command to see the options.\n " )
73+ else :
74+ click .echo ('\n ' + json_data ['data' ]['removeTeamsFromProject' ]['error' ]['message' ] + '\n ' )
6375 else :
6476 data_success = json_data ['data' ]['removeTeamsFromProject' ]['succeeded' ]
6577 data_failed = json_data ['data' ]['removeTeamsFromProject' ]['failed' ]
@@ -68,12 +80,14 @@ def remove_groups_from_project(project_pk: int, group_pk: list, auth: str):
6880 successful_groups = []
6981 for s in data_success :
7082 successful_groups .append (s .get ('pk' ))
71- click .echo ("\n The following groups were successfully removed from project %s: %s" % (project_pk , successful_groups ))
83+ click .echo ("\n The following groups were successfully removed from project %s: %s\n " % (project_pk , successful_groups ))
7284
7385 if data_failed :
7486 click .echo ('\n The following groups could not be removed from project %s:' % (project_pk ))
7587 for f in data_failed :
76- click .echo ("%s - %s \n " % (f .get ('teamPk' ), f .get ('message' )))
88+ click .echo ("%s - %s" % (f .get ('teamPk' ), f .get ('message' )))
89+
90+ click .echo ("\n " )
7791
7892@click .option ('-p' , '--project-pk' , type = int , help = 'Pk of the project you want to add collaborators to' )
7993@click .option ('-e' , '--email' , type = str , multiple = True , help = 'Use this flag for each email address you want added to your project' )
@@ -86,21 +100,30 @@ def add_collabs_to_project(project_pk: int, email: list, auth: str):
86100 r , json_data = utils .make_request (auth , query , params )
87101
88102 if r .status_code != 200 :
89- click .echo ('\n ' + json_data ['data' ]['addCollaboratorsToProject' ]['error' ]['message' ] + '\n ' )
103+ if not project_pk :
104+ click .echo ("\n Looks like you might be missing some args, add `--help` to your command to see the options.\n " )
105+ else :
106+ click .echo ('\n ' + json_data ['data' ]['addCollaboratorsToProject' ]['error' ]['message' ] + '\n ' )
90107 else :
91- data_success = json_data ['data' ]['addCollaboratorsToProject' ]['succeeded' ]
92- data_failed = json_data ['data' ]['addCollaboratorsToProject' ]['failed' ]
108+ # status_code 200 without all args
109+ if not email :
110+ click .echo ("\n Looks like you might be missing some args, add `--help` to your command to see the options.\n " )
111+ else :
112+ data_success = json_data ['data' ]['addCollaboratorsToProject' ]['succeeded' ]
113+ data_failed = json_data ['data' ]['addCollaboratorsToProject' ]['failed' ]
93114
94- if data_success :
95- successful_emails = []
96- for s in data_success :
97- successful_emails .append (s .get ('email' ))
98- click .echo ("\n The following people were successfully added to project %s: %s" % (pk , ', ' .join (successful_emails )))
115+ if data_success :
116+ successful_emails = []
117+ for s in data_success :
118+ successful_emails .append (s .get ('email' ))
119+ click .echo ("\n The following people were successfully added to project %s: %s" % (project_pk , ', ' .join (successful_emails )))
99120
100- if data_failed :
101- click .echo ('\n The following people could not be added to project %s:' % (pk ))
102- for f in data_failed :
103- click .echo ("%s - '%s' \n " % (f .get ('email' ), f .get ('message' )))
121+ if data_failed :
122+ click .echo ('\n The following people could not be added to project %s for the following reasons:' % (project_pk ))
123+ for f in data_failed :
124+ click .echo ("%s - '%s'" % (f .get ('email' ), f .get ('message' )))
125+
126+ click .echo ("\n " )
104127
105128
106129@click .option ('-p' , '--project-pk' , type = int , help = 'Pk of the project you want to remove collaborators from' )
@@ -114,16 +137,25 @@ def remove_collabs_from_project(project_pk: int, email: list, auth: str):
114137 r , json_data = utils .make_request (auth , query , params )
115138
116139 if r .status_code != 200 :
117- click .echo ('\n ' + json_data ['data' ]['removeCollaboratorsFromProject' ]['error' ]['message' ] + '\n ' )
140+ if not project_pk :
141+ click .echo ("\n Looks like you might be missing some args, add `--help` to your command to see the options.\n " )
142+ else :
143+ click .echo ('\n ' + json_data ['data' ]['removeCollaboratorsFromProject' ]['error' ]['message' ] + '\n ' )
118144 else :
119- if json_data ['data' ]['removeCollaboratorsFromProject' ]['succeeded' ]:
120- click .echo ("\n The following people were successfully removed from project %s: %s" % (pk , ', ' .join (data_success )))
145+ if not email :
146+ click .echo ("\n Looks like you might be missing some args, add `--help` to your command to see the options.\n " )
147+ else :
148+ data_success = json_data ['data' ]['removeCollaboratorsFromProject' ]['succeeded' ]
149+ if json_data ['data' ]['removeCollaboratorsFromProject' ]['succeeded' ]:
150+ click .echo ("\n The following people were successfully removed from project %s: %s" % (project_pk , data_success ))
121151
122- data_failed = json_data ['data' ]['removeCollaboratorsFromProject' ]['failed' ]
123- if data_failed :
124- click .echo ('\n The following people could not be removed from project %s:' % (pk ))
125- for f in data_failed :
126- click .echo ("%s - '%s' \n " % (f .get ('email' ), f .get ('message' )))
152+ data_failed = json_data ['data' ]['removeCollaboratorsFromProject' ]['failed' ]
153+ if data_failed :
154+ click .echo ('\n The following people could not be removed from project %s for the following reasons:' % (project_pk ))
155+ for f in data_failed :
156+ click .echo ("%s - '%s'" % (f .get ('email' ), f .get ('message' )))
157+
158+ click .echo ("\n " )
127159
128160
129161@click .option ('-n' , '--name' , type = str , help = 'Name of project' )
@@ -132,16 +164,26 @@ def remove_collabs_from_project(project_pk: int, email: list, auth: str):
132164@click .command ()
133165def create_project (name : str , password : str , auth : str ):
134166 """Create a new project"""
135- params = {'name' : name ,'password' : password }
136- if not password :
137- params ['password' ] = ''
138- query = project_queries .create_project_query
139- r , json_data = utils .make_request (auth , query , params )
140-
141- if r .status_code != 200 :
142- click .echo ('\n ' + 'A new project could not be created at this time."' + '\n ' )
167+ if not name :
168+ click .echo ("\n Looks like you might be missing some args, add `--help` to your command to see the options.\n " )
143169 else :
144- click .echo ('\n "%s" has been successfully created in your Marvel account \n ' % name )
170+ user_query = workspace_queries .get_billing_info_query
171+ req , json_data_user = utils .make_request (auth , user_query )
172+ plan = json_data_user ['data' ]['user' ]['company' ]['billing' ]['plan' ]['title' ]
173+ proj_used = json_data_user ['data' ]['user' ]['company' ]['billing' ]['projectQuantityUsed' ]
174+ if plan == 'Free' and proj_used == 1 :
175+ click .echo ("\n You have maxed out your allowances, either delete a project then run the command again or upgrade for unlimited projects: https://marvelapp.com/plans \n " )
176+ else :
177+ params = {'name' : name ,'password' : password }
178+ if not password :
179+ params ['password' ] = ''
180+ query = project_queries .create_project_query
181+ r , json_data = utils .make_request (auth , query , params )
182+
183+ if r .status_code != 200 :
184+ click .echo ('\n ' + 'A new project could not be created at this time."' + '\n ' )
185+ else :
186+ click .echo ('\n "%s" has been successfully created in your Marvel account \n ' % name )
145187
146188@click .option ('-a' , '--auth' , type = str , help = 'Auth your request' )
147189@click .command ()
@@ -160,7 +202,9 @@ def get_personal_projects(auth: str):
160202 urls .append (url )
161203
162204 project_count = len (json_data ['data' ]['user' ]['projects' ]['edges' ])
163- click .echo ('\n You have %s project(s)' % project_count )
205+ click .echo ('\n You have %s project(s): ' % project_count )
164206
165207 for url in urls :
166208 click .echo (url )
209+
210+ click .echo ("\n " )
0 commit comments