4
4
import logging
5
5
from datetime import datetime
6
6
from pathlib import Path
7
- from typing import Optional
7
+ from typing import Annotated , Optional
8
8
9
9
import aiohttp
10
10
import typer
30
30
31
31
@app .command ()
32
32
async 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 ,
39
41
):
40
42
"""Persist a file from IPFS on aleph.im."""
41
43
@@ -58,12 +60,14 @@ async def pin(
58
60
59
61
@app .command ()
60
62
async 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 ,
67
71
):
68
72
"""Upload and store a file on aleph.im."""
69
73
@@ -97,14 +101,14 @@ async def upload(
97
101
98
102
@app .command ()
99
103
async 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 ,
108
112
) -> Optional [StoredContent ]:
109
113
"""Download a file from aleph.im or display related infos."""
110
114
@@ -142,14 +146,19 @@ async def download(
142
146
143
147
@app .command ()
144
148
async 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 ,
153
162
):
154
163
"""forget a file and his message on aleph.im."""
155
164
@@ -225,20 +234,23 @@ def _show_files(files_data: dict) -> None:
225
234
console .print (table )
226
235
227
236
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."
239
251
),
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 ,
242
254
):
243
255
"""List all files for a given address"""
244
256
account : AccountFromPrivateKey = _load_account (private_key , private_key_file )
0 commit comments