44import logging
55from datetime import datetime
66from pathlib import Path
7- from typing import Optional
7+ from typing import Annotated , Optional
88
99import aiohttp
1010import typer
3030
3131@app .command ()
3232async def pin (
33- item_hash : str = typer .Argument (..., help = "IPFS hash to pin on aleph.im" ),
34- channel : Optional [str ] = typer .Option (default = settings .DEFAULT_CHANNEL , help = help_strings .CHANNEL ),
35- private_key : Optional [str ] = typer .Option (settings .PRIVATE_KEY_STRING , help = help_strings .PRIVATE_KEY ),
36- private_key_file : Optional [Path ] = typer .Option (settings .PRIVATE_KEY_FILE , help = help_strings .PRIVATE_KEY_FILE ),
37- ref : Optional [str ] = typer .Option (None , help = help_strings .REF ),
38- debug : bool = False ,
33+ item_hash : Annotated [str , typer .Argument (help = "IPFS hash to pin on aleph.im" )],
34+ channel : Annotated [Optional [str ], typer .Option (help = help_strings .CHANNEL )] = settings .DEFAULT_CHANNEL ,
35+ private_key : Annotated [Optional [str ], typer .Option (help = help_strings .PRIVATE_KEY )] = settings .PRIVATE_KEY_STRING ,
36+ private_key_file : Annotated [
37+ Optional [Path ], typer .Option (help = help_strings .PRIVATE_KEY_FILE )
38+ ] = settings .PRIVATE_KEY_FILE ,
39+ ref : Annotated [Optional [str ], typer .Option (help = help_strings .REF )] = None ,
40+ debug : Annotated [bool , typer .Option ()] = False ,
3941):
4042 """Persist a file from IPFS on aleph.im."""
4143
@@ -58,12 +60,14 @@ async def pin(
5860
5961@app .command ()
6062async def upload (
61- path : Path = typer .Argument (..., help = "Path of the file to upload" ),
62- channel : Optional [str ] = typer .Option (default = settings .DEFAULT_CHANNEL , help = help_strings .CHANNEL ),
63- private_key : Optional [str ] = typer .Option (settings .PRIVATE_KEY_STRING , help = help_strings .PRIVATE_KEY ),
64- private_key_file : Optional [Path ] = typer .Option (settings .PRIVATE_KEY_FILE , help = help_strings .PRIVATE_KEY_FILE ),
65- ref : Optional [str ] = typer .Option (None , help = help_strings .REF ),
66- debug : bool = False ,
63+ path : Annotated [Path , typer .Argument (help = "Path of the file to upload" )],
64+ channel : Annotated [Optional [str ], typer .Option (help = help_strings .CHANNEL )] = settings .DEFAULT_CHANNEL ,
65+ private_key : Annotated [Optional [str ], typer .Option (help = help_strings .PRIVATE_KEY )] = settings .PRIVATE_KEY_STRING ,
66+ private_key_file : Annotated [
67+ Optional [Path ], typer .Option (help = help_strings .PRIVATE_KEY_FILE )
68+ ] = settings .PRIVATE_KEY_FILE ,
69+ ref : Annotated [Optional [str ], typer .Option (help = help_strings .REF )] = None ,
70+ debug : Annotated [bool , typer .Option ()] = False ,
6771):
6872 """Upload and store a file on aleph.im."""
6973
@@ -97,14 +101,14 @@ async def upload(
97101
98102@app .command ()
99103async def download (
100- hash : str = typer .Argument (..., help = "hash to download from aleph." ),
101- use_ipfs : bool = typer .Option (default = False , help = "Download using IPFS instead of storage" ),
102- output_path : Path = typer .Option (Path ( "." ), help = "Output directory path" ),
103- file_name : str = typer .Option (None , help = "Output file name (without extension)" ),
104- file_extension : str = typer .Option (None , help = "Output file extension" ),
105- only_info : bool = False ,
106- verbose : bool = True ,
107- debug : bool = False ,
104+ hash : Annotated [ str , typer .Argument (help = "hash to download from aleph." )] ,
105+ use_ipfs : Annotated [ bool , typer .Option (help = "Download using IPFS instead of storage" )] = False ,
106+ output_path : Annotated [ Path , typer .Option (help = "Output directory path" )] = Path ( ". " ),
107+ file_name : Annotated [ Optional [ str ], typer .Option (help = "Output file name (without extension)" )] = None ,
108+ file_extension : Annotated [ Optional [ str ], typer .Option (help = "Output file extension" )] = None ,
109+ only_info : Annotated [ bool , typer . Option ()] = False ,
110+ verbose : Annotated [ bool , typer . Option ()] = True ,
111+ debug : Annotated [ bool , typer . Option ()] = False ,
108112) -> Optional [StoredContent ]:
109113 """Download a file from aleph.im or display related infos."""
110114
@@ -142,14 +146,19 @@ async def download(
142146
143147@app .command ()
144148async def forget (
145- item_hash : str = typer .Argument (
146- ..., help = "Hash(es) to forget. Must be a comma separated list. Example: `123...abc` or `123...abc,456...xyz`"
147- ),
148- reason : str = typer .Argument ("User deletion" , help = "reason to forget" ),
149- channel : Optional [str ] = typer .Option (default = settings .DEFAULT_CHANNEL , help = help_strings .CHANNEL ),
150- private_key : Optional [str ] = typer .Option (settings .PRIVATE_KEY_STRING , help = help_strings .PRIVATE_KEY ),
151- private_key_file : Optional [Path ] = typer .Option (settings .PRIVATE_KEY_FILE , help = help_strings .PRIVATE_KEY_FILE ),
152- debug : bool = False ,
149+ item_hash : Annotated [
150+ str ,
151+ typer .Argument (
152+ help = "Hash(es) to forget. Must be a comma separated list. Example: `123...abc` or `123...abc,456...xyz`"
153+ ),
154+ ],
155+ reason : Annotated [str , typer .Argument (help = "reason to forget" )] = "User deletion" ,
156+ channel : Annotated [Optional [str ], typer .Option (help = help_strings .CHANNEL )] = settings .DEFAULT_CHANNEL ,
157+ private_key : Annotated [Optional [str ], typer .Option (help = help_strings .PRIVATE_KEY )] = settings .PRIVATE_KEY_STRING ,
158+ private_key_file : Annotated [
159+ Optional [Path ], typer .Option (help = help_strings .PRIVATE_KEY_FILE )
160+ ] = settings .PRIVATE_KEY_FILE ,
161+ debug : Annotated [bool , typer .Option ()] = False ,
153162):
154163 """forget a file and his message on aleph.im."""
155164
@@ -225,20 +234,23 @@ def _show_files(files_data: dict) -> None:
225234 console .print (table )
226235
227236
228- @app .command ()
229- async def list (
230- address : Optional [str ] = typer .Option (None , help = "Address" ),
231- private_key : Optional [str ] = typer .Option (settings .PRIVATE_KEY_STRING , help = help_strings .PRIVATE_KEY ),
232- private_key_file : Optional [Path ] = typer .Option (settings .PRIVATE_KEY_FILE , help = help_strings .PRIVATE_KEY_FILE ),
233- pagination : int = typer .Option (100 , help = "Maximum number of files to return." ),
234- page : int = typer .Option (1 , help = "Offset in pages." ),
235- sort_order : int = typer .Option (
236- - 1 ,
237- help = (
238- "Order in which files should be listed: -1 means most recent messages first, 1 means older messages first."
237+ @app .command (name = "list" )
238+ async def list_files (
239+ address : Annotated [Optional [str ], typer .Option (help = "Address" )] = None ,
240+ private_key : Annotated [Optional [str ], typer .Option (help = help_strings .PRIVATE_KEY )] = settings .PRIVATE_KEY_STRING ,
241+ private_key_file : Annotated [
242+ Optional [Path ], typer .Option (help = help_strings .PRIVATE_KEY_FILE )
243+ ] = settings .PRIVATE_KEY_FILE ,
244+ pagination : Annotated [int , typer .Option (help = "Maximum number of files to return." )] = 100 ,
245+ page : Annotated [int , typer .Option (help = "Offset in pages." )] = 1 ,
246+ sort_order : Annotated [
247+ int ,
248+ typer .Option (
249+ help = "Order in which files should be listed: -1 means most recent messages first,"
250+ " 1 means older messages first."
239251 ),
240- ) ,
241- json : bool = typer .Option (default = False , help = "Print as json instead of rich table" ),
252+ ] = - 1 ,
253+ json : Annotated [ bool , typer .Option (help = "Print as json instead of rich table" )] = False ,
242254):
243255 """List all files for a given address"""
244256 account : AccountFromPrivateKey = _load_account (private_key , private_key_file )
0 commit comments