2323# Internationalization
2424gettext .install ("submit50" , str (files ("submit50" ).joinpath ("locale" )))
2525
26+ LOGGER = logging .getLogger ("submit50" )
27+
2628SUBMIT_URL = "https://submit.cs50.io"
2729
2830class LogLevel (enum .IntEnum ):
@@ -243,6 +245,12 @@ def main():
243245 '\n info: adds all commands run.'
244246 '\n debug: adds the output of all commands run.' )
245247 )
248+ parser .add_argument ("--https" ,
249+ action = "store_true" ,
250+ help = _ ("force authentication via HTTPS" ))
251+ parser .add_argument ("--ssh" ,
252+ action = "store_true" ,
253+ help = _ ("force authentication via SSH" ))
246254 parser .add_argument (
247255 "-V" , "--version" ,
248256 action = "version" ,
@@ -260,8 +268,30 @@ def main():
260268 check_announcements ()
261269 check_version ()
262270 check_slug_year (args .slug )
263-
264- user_name , commit_hash , message = lib50 .push ("submit50" , args .slug , CONFIG_LOADER , prompt = prompt )
271+
272+ # Decide whether to force HTTPS or SSH authentication
273+ if args .https and args .ssh :
274+ LOGGER .warning (_ ("--https and --ssh have no effect when used together" ))
275+ auth_method = None
276+ elif args .https :
277+ auth_method = "https"
278+ elif args .ssh :
279+ auth_method = "ssh"
280+ else :
281+ auth_method = None
282+
283+ try :
284+ user_name , commit_hash , message = lib50 .push ("submit50" , args .slug , CONFIG_LOADER , prompt = prompt , auth_method = auth_method )
285+ except lib50 .ConnectionError :
286+ LOGGER .debug (traceback .format_exc ())
287+ if not os .environ .get ("CODESPACES" ):
288+ raise Error (_ (
289+ "submit50 failed to authenticate your Github account. Please make sure you are connected to the internet and try again."
290+ ))
291+ except Exception as e :
292+ LOGGER .debug (traceback .format_exc ())
293+ raise Error (_ ("Sorry, something's wrong, please try again.\n "
294+ "If the problem persists, please visit our status page https://cs50.statuspage.io for more information." )) from e
265295 print (message )
266296
267297if __name__ == "__main__" :
0 commit comments