2020
2121
2222logger = logging .getLogger ("mega" )
23-
24- Verbose = Annotated [
25- int ,
26- Parameter (
27- name = ["-v" , "--verbose" ], count = True , help = "Increase verbosity (-v shows debug logs, -vv shows HTTP traffic)"
28- ),
29- ]
30-
31-
32- def parse_verbose (count : int ) -> None :
33- if count > 1 :
34- LOG_HTTP_TRAFFIC .set (True )
35-
36- level = logging .DEBUG if count else logging .INFO
37- setup_logger (level )
38-
23+ CWD = Path .cwd ()
3924
4025app = App (
4126 help = (
@@ -45,7 +30,26 @@ def parse_verbose(count: int) -> None:
4530 ),
4631 version = __version__ ,
4732)
48- CWD = Path .cwd ()
33+
34+
35+ @app .meta .default
36+ def verbose (
37+ * tokens : Annotated [str , Parameter (show = False , allow_leading_hyphen = True )],
38+ verbose : Annotated [
39+ int ,
40+ Parameter (
41+ name = ["-v" , "--verbose" ],
42+ count = True ,
43+ help = "Increase verbosity (-v shows debug logs, -vv shows HTTP traffic)" ,
44+ ),
45+ ] = 0 ,
46+ ) -> None :
47+ if verbose > 1 :
48+ LOG_HTTP_TRAFFIC .set (True )
49+
50+ level = logging .DEBUG if verbose else logging .INFO
51+ setup_logger (level )
52+ app (tokens )
4953
5054
5155@contextlib .asynccontextmanager
@@ -68,9 +72,9 @@ async def transfer_it(url: str, output_dir: Path) -> None:
6872
6973
7074@app .command ()
71- async def download (url : str , output_dir : Path = CWD , * , verbose : Verbose = 0 ) -> None :
75+ async def download (url : str , output_dir : Path = CWD ) -> None :
7276 """Download a public file or folder by its URL (transfer.it / mega.nz)"""
73- parse_verbose ( verbose )
77+
7478 site = Site (yarl .URL (url ).origin ())
7579 if site is Site .TRANSFER_IT :
7680 return await transfer_it (url , output_dir )
@@ -84,9 +88,9 @@ async def download(url: str, output_dir: Path = CWD, *, verbose: Verbose = 0) ->
8488
8589
8690@app .command ()
87- async def dump (output_dir : Path = CWD , * , verbose : Verbose = 0 ) -> None :
91+ async def dump (output_dir : Path = CWD ) -> None :
8892 """Dump a copy of your filesystem to disk"""
89- parse_verbose ( verbose )
93+
9094 async with connect () as mega :
9195 fs = await mega .get_filesystem ()
9296 out = output_dir / "filesystem.json"
@@ -96,9 +100,9 @@ async def dump(output_dir: Path = CWD, *, verbose: Verbose = 0) -> None:
96100
97101
98102@app .command ()
99- async def stats (* , verbose : Verbose = 0 ) -> None :
103+ async def stats () -> None :
100104 """Show account stats"""
101- parse_verbose ( verbose )
105+
102106 async with connect () as mega :
103107 stats = await mega .get_account_stats ()
104108 logger .info (f"Account stats for { env .EMAIL or 'TEMP ACCOUNT' } :" )
@@ -110,9 +114,9 @@ async def stats(*, verbose: Verbose = 0) -> None:
110114
111115
112116@app .command ()
113- async def upload (file_path : Path , * , verbose : Verbose = 0 ) -> None :
117+ async def upload (file_path : Path ) -> None :
114118 """Upload a file to your account"""
115- parse_verbose ( verbose )
119+
116120 async with connect () as mega :
117121 if not env .EMAIL :
118122 logger .warning ("Files uploaded by a temp account can not be exported" )
@@ -144,4 +148,4 @@ async def download_folder(mega: MegaNzClient, url: str, output: Path) -> None:
144148
145149
146150if __name__ == "__main_" :
147- app ()
151+ app . meta ()
0 commit comments