33import os
44import subprocess
55from pathlib import Path
6- from typing import List , Optional , Tuple , Union
76from urllib .parse import urlparse
87
98import click
@@ -103,7 +102,7 @@ def view(self, challenge: str, color=True) -> int:
103102 if not challenge_instance :
104103 return 1
105104
106- with open (challenge_instance .challenge_file_path , "r" ) as challenge_yml_file :
105+ with open (challenge_instance .challenge_file_path ) as challenge_yml_file :
107106 challenge_yml = challenge_yml_file .read ()
108107
109108 if color :
@@ -120,7 +119,12 @@ def templates(self) -> int:
120119 return TemplatesCommand .list ()
121120
122121 def add (
123- self , repo : str , directory : str = None , branch : str = None , force : bool = False , yaml_path : str = None
122+ self ,
123+ repo : str ,
124+ directory : str | None = None ,
125+ branch : str | None = None ,
126+ force : bool = False ,
127+ yaml_path : str | None = None ,
124128 ) -> int :
125129 log .debug (f"add: { repo } (directory={ directory } , branch={ branch } , force={ force } , yaml_path={ yaml_path } )" )
126130 config = Config ()
@@ -207,7 +211,7 @@ def add(
207211 click .secho (f"Could not process the challenge path: '{ repo } '" , fg = "red" )
208212 return 1
209213
210- def push (self , challenge : str = None , no_auto_pull : bool = False , quiet = False ) -> int :
214+ def push (self , challenge : str | None = None , no_auto_pull : bool = False , quiet = False ) -> int :
211215 log .debug (f"push: (challenge={ challenge } , no_auto_pull={ no_auto_pull } , quiet={ quiet } )" )
212216 config = Config ()
213217
@@ -332,7 +336,7 @@ def push(self, challenge: str = None, no_auto_pull: bool = False, quiet=False) -
332336
333337 return 1
334338
335- def pull (self , challenge : str = None , strategy : str = "fast-forward" , quiet : bool = False ) -> int :
339+ def pull (self , challenge : str | None = None , strategy : str = "fast-forward" , quiet : bool = False ) -> int :
336340 log .debug (f"pull: (challenge={ challenge } , quiet={ quiet } )" )
337341 config = Config ()
338342
@@ -460,7 +464,7 @@ def pull(self, challenge: str = None, strategy: str = "fast-forward", quiet: boo
460464
461465 return 1
462466
463- def restore (self , challenge : str = None ) -> int :
467+ def restore (self , challenge : str | None = None ) -> int :
464468 log .debug (f"restore: (challenge={ challenge } )" )
465469 config = Config ()
466470
@@ -562,7 +566,7 @@ def restore(self, challenge: str = None) -> int:
562566 return 1
563567
564568 def install (
565- self , challenge : str = None , force : bool = False , hidden : bool = False , ignore : Union [ str , Tuple [str ] ] = ()
569+ self , challenge : str | None = None , force : bool = False , hidden : bool = False , ignore : str | tuple [str ] = ()
566570 ) -> int :
567571 log .debug (f"install: (challenge={ challenge } , force={ force } , hidden={ hidden } , ignore={ ignore } )" )
568572
@@ -638,7 +642,7 @@ def install(
638642
639643 return 1
640644
641- def sync (self , challenge : str = None , ignore : Union [ str , Tuple [str ] ] = ()) -> int :
645+ def sync (self , challenge : str | None = None , ignore : str | tuple [str ] = ()) -> int :
642646 log .debug (f"sync: (challenge={ challenge } , ignore={ ignore } )" )
643647
644648 if challenge :
@@ -672,7 +676,7 @@ def sync(self, challenge: str = None, ignore: Union[str, Tuple[str]] = ()) -> in
672676 continue
673677
674678 click .secho (
675- f"Syncing '{ challenge_name } ' (" f" { challenge_instance .challenge_file_path } " " ) ..." ,
679+ f"Syncing '{ challenge_name } ' ({ challenge_instance .challenge_file_path } ) ..." ,
676680 fg = "blue" ,
677681 )
678682 try :
@@ -694,8 +698,8 @@ def sync(self, challenge: str = None, ignore: Union[str, Tuple[str]] = ()) -> in
694698
695699 def deploy (
696700 self ,
697- challenge : str = None ,
698- host : str = None ,
701+ challenge : str | None = None ,
702+ host : str | None = None ,
699703 skip_login : bool = False ,
700704 ) -> int :
701705 log .debug (f"deploy: (challenge={ challenge } , host={ host } , skip_login={ skip_login } )" )
@@ -836,7 +840,7 @@ def deploy(
836840
837841 def lint (
838842 self ,
839- challenge : str = None ,
843+ challenge : str | None = None ,
840844 skip_hadolint : bool = False ,
841845 flag_format : str = "flag{" ,
842846 ) -> int :
@@ -857,7 +861,7 @@ def lint(
857861 click .secho ("Success! Lint didn't find any issues!" , fg = "green" )
858862 return 0
859863
860- def healthcheck (self , challenge : Optional [ str ] = None ) -> int :
864+ def healthcheck (self , challenge : str | None = None ) -> int :
861865 log .debug (f"healthcheck: (challenge={ challenge } )" )
862866
863867 challenge_instance = self ._resolve_single_challenge (challenge )
@@ -922,10 +926,10 @@ def healthcheck(self, challenge: Optional[str] = None) -> int:
922926
923927 def mirror (
924928 self ,
925- challenge : str = None ,
929+ challenge : str | None = None ,
926930 files_directory : str = "dist" ,
927931 skip_verify : bool = False ,
928- ignore : Union [ str , Tuple [str ] ] = (),
932+ ignore : str | tuple [str ] = (),
929933 create : bool = False ,
930934 ) -> int :
931935 log .debug (
@@ -991,7 +995,7 @@ def mirror(
991995
992996 return 1
993997
994- def verify (self , challenge : str = None , ignore : Tuple [str ] = ()) -> int :
998+ def verify (self , challenge : str | None = None , ignore : tuple [str ] = ()) -> int :
995999 log .debug (f"verify: (challenge={ challenge } , ignore={ ignore } )" )
9961000
9971001 if challenge :
@@ -1056,7 +1060,7 @@ def verify(self, challenge: str = None, ignore: Tuple[str] = ()) -> int:
10561060
10571061 return 1
10581062
1059- def format (self , challenge : Optional [ str ] = None ) -> int :
1063+ def format (self , challenge : str | None = None ) -> int :
10601064 log .debug (f"format: (challenge={ challenge } )" )
10611065
10621066 if challenge :
@@ -1090,7 +1094,7 @@ def format(self, challenge: Optional[str] = None) -> int:
10901094 return 1
10911095
10921096 @staticmethod
1093- def _resolve_single_challenge (challenge : Optional [ str ] = None ) -> Optional [ Challenge ] :
1097+ def _resolve_single_challenge (challenge : str | None = None ) -> Challenge | None :
10941098 # if a challenge is specified
10951099 if challenge :
10961100 # check if it's a path to challenge.yml, or the current directory
@@ -1113,10 +1117,10 @@ def _resolve_single_challenge(challenge: Optional[str] = None) -> Optional[Chall
11131117 return Challenge (challenge_path )
11141118 except ChallengeException as e :
11151119 click .secho (str (e ), fg = "red" )
1116- return
1120+ return None
11171121
11181122 @staticmethod
1119- def _resolve_all_challenges () -> List [Challenge ]:
1123+ def _resolve_all_challenges () -> list [Challenge ]:
11201124 config = Config ()
11211125 challenge_keys = config .challenges .keys ()
11221126
0 commit comments