|
16 | 16 | --server-url: URL of the FileCloud server. |
17 | 17 | """ |
18 | 18 |
|
| 19 | +import os |
19 | 20 | from dataclasses import dataclass |
20 | 21 | from pathlib import Path |
| 22 | + |
21 | 23 | import click |
22 | | -import os |
23 | 24 |
|
24 | 25 | from filecloudapi.fcserver import FCServer |
25 | 26 |
|
| 27 | + |
26 | 28 | @dataclass |
27 | 29 | class ServerConfig: |
28 | 30 | server_url: str |
29 | 31 | username: str |
30 | 32 | password: str |
31 | 33 |
|
32 | | -@click.option('-s', '--server-url', prompt=True, hide_input=False, help='URL of the FileCloud server') |
33 | | -@click.option('-u', '--username', prompt=True, hide_input=False, help='Username for authentication') |
34 | | -@click.option('-p', '--password', prompt=True, hide_input=True, default=lambda: os.environ.get('FILECLOUD_PASSWORD', ''), help='Password for authentication') |
| 34 | + |
| 35 | +@click.option( |
| 36 | + "-s", |
| 37 | + "--server-url", |
| 38 | + prompt=True, |
| 39 | + hide_input=False, |
| 40 | + help="URL of the FileCloud server", |
| 41 | +) |
| 42 | +@click.option( |
| 43 | + "-u", |
| 44 | + "--username", |
| 45 | + prompt=True, |
| 46 | + hide_input=False, |
| 47 | + help="Username for authentication", |
| 48 | +) |
| 49 | +@click.option( |
| 50 | + "-p", |
| 51 | + "--password", |
| 52 | + prompt=True, |
| 53 | + hide_input=True, |
| 54 | + default=lambda: os.environ.get("FILECLOUD_PASSWORD", ""), |
| 55 | + help="Password for authentication", |
| 56 | +) |
35 | 57 | @click.group() |
36 | 58 | @click.pass_context |
37 | 59 | def cli(ctx, server_url: str, username: str, password: str): |
38 | 60 | ctx.obj = ServerConfig(server_url, username, password) |
39 | 61 | pass |
40 | 62 |
|
| 63 | + |
41 | 64 | def create_fcserver(config: ServerConfig) -> FCServer: |
42 | | - return FCServer(config.server_url, email=None, username=config.username, password=config.password) |
| 65 | + return FCServer( |
| 66 | + config.server_url, |
| 67 | + email=None, |
| 68 | + username=config.username, |
| 69 | + password=config.password, |
| 70 | + ) |
| 71 | + |
43 | 72 |
|
44 | 73 | @cli.command() |
45 | | -@click.option('-l', '--local', type=Path, required=True, help='Path to the local file to be uploaded') |
46 | | -@click.option('-r', '--remote', type=str, required=True, help='Remote path where the file should be uploaded on the FileCloud server') |
| 74 | +@click.option( |
| 75 | + "-l", |
| 76 | + "--local", |
| 77 | + type=Path, |
| 78 | + required=True, |
| 79 | + help="Path to the local file to be uploaded", |
| 80 | +) |
| 81 | +@click.option( |
| 82 | + "-r", |
| 83 | + "--remote", |
| 84 | + type=str, |
| 85 | + required=True, |
| 86 | + help="Remote path where the file should be uploaded on the FileCloud server", |
| 87 | +) |
47 | 88 | @click.pass_obj |
48 | 89 | def upload_file(config: ServerConfig, local: Path, remote: str): |
49 | 90 | fcserver = create_fcserver(config) |
50 | 91 | fcserver.upload_file(local, remote) |
51 | 92 |
|
52 | 93 |
|
53 | | -if __name__ == '__main__': # pragma: no cover |
| 94 | +if __name__ == "__main__": # pragma: no cover |
54 | 95 | cli() |
0 commit comments