dronefly-cli 0.2.6__tar.gz → 0.3.0.dev0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {dronefly_cli-0.2.6 → dronefly_cli-0.3.0.dev0}/PKG-INFO +4 -3
- {dronefly_cli-0.2.6 → dronefly_cli-0.3.0.dev0}/dronefly_cli/main.py +55 -9
- {dronefly_cli-0.2.6 → dronefly_cli-0.3.0.dev0}/pyproject.toml +2 -2
- {dronefly_cli-0.2.6 → dronefly_cli-0.3.0.dev0}/LICENSE +0 -0
- {dronefly_cli-0.2.6 → dronefly_cli-0.3.0.dev0}/README.md +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
2
|
Name: dronefly-cli
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0.dev0
|
|
4
4
|
Summary: Dronefly command-line interface
|
|
5
5
|
License: AGPL-3.0-or-later
|
|
6
6
|
Author: Ben Armstrong
|
|
@@ -9,7 +9,8 @@ Requires-Python: >=3.11,<3.13
|
|
|
9
9
|
Classifier: License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)
|
|
10
10
|
Classifier: Programming Language :: Python :: 3
|
|
11
11
|
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
-
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Requires-Dist: dronefly-core (==0.5.0.dev0)
|
|
13
14
|
Requires-Dist: pyreadline3 (>=3.4.1,<4.0.0)
|
|
14
15
|
Requires-Dist: rich (>=13.2,<14.0)
|
|
15
16
|
Description-Content-Type: text/markdown
|
|
@@ -3,21 +3,60 @@ import asyncio
|
|
|
3
3
|
import os
|
|
4
4
|
import sys
|
|
5
5
|
import readline
|
|
6
|
+
from inspect import getmembers, isroutine
|
|
6
7
|
|
|
7
8
|
from dronefly.core import Commands, Format
|
|
8
9
|
from dronefly.core.models import Config, User
|
|
9
10
|
from dronefly.core.commands import ArgumentError, CommandError, Context
|
|
10
11
|
from dronefly.core.constants import INAT_USER_DEFAULT_PARAMS
|
|
11
12
|
from rich.console import Console
|
|
13
|
+
from rich.markdown import Markdown
|
|
12
14
|
|
|
13
15
|
|
|
14
16
|
console = Console()
|
|
15
|
-
commands = Commands(format=Format.rich)
|
|
16
17
|
histfile = os.path.expanduser("~/.dronefly_history")
|
|
17
18
|
histfile_size = 1000
|
|
18
19
|
|
|
19
20
|
|
|
20
|
-
async def
|
|
21
|
+
async def help(ctx, *args):
|
|
22
|
+
"""Show help
|
|
23
|
+
Usage:
|
|
24
|
+
help Show help index
|
|
25
|
+
help <command> Show help for command""" # noqa: E501
|
|
26
|
+
|
|
27
|
+
def format_help_index_command(command, command_width):
|
|
28
|
+
command_help = f"{command[0].replace('_',' ').ljust(command_width)}"
|
|
29
|
+
if command[1].__doc__:
|
|
30
|
+
command_help += " " + command[1].__doc__.splitlines()[0]
|
|
31
|
+
return command_help
|
|
32
|
+
|
|
33
|
+
if len(args) == 0:
|
|
34
|
+
commands = [
|
|
35
|
+
*(
|
|
36
|
+
member
|
|
37
|
+
for member in getmembers(Commands, predicate=isroutine)
|
|
38
|
+
if member[0][0] != "_"
|
|
39
|
+
),
|
|
40
|
+
("help", help),
|
|
41
|
+
]
|
|
42
|
+
commands.sort(key=lambda x: x[0])
|
|
43
|
+
longest = max(len(member[0]) for member in commands)
|
|
44
|
+
response = "\n".join(
|
|
45
|
+
format_help_index_command(command, longest) for command in commands
|
|
46
|
+
)
|
|
47
|
+
return response
|
|
48
|
+
command_name = "_".join(args)
|
|
49
|
+
if command_name[0] != "_":
|
|
50
|
+
if command_name == "help":
|
|
51
|
+
command = help
|
|
52
|
+
else:
|
|
53
|
+
command = getattr(Commands, command_name, None)
|
|
54
|
+
if callable(command):
|
|
55
|
+
return f"Command: {command_name.replace('_', ' ')}\nDescription: {command.__doc__}"
|
|
56
|
+
return f"No help for: {' '.join(args)}"
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
async def do_command(commands, command_str: str, ctx: Context, *args):
|
|
21
60
|
try:
|
|
22
61
|
command = None
|
|
23
62
|
_args = [*args]
|
|
@@ -26,12 +65,14 @@ async def do_command(command_str: str, ctx: Context, *args):
|
|
|
26
65
|
command = getattr(commands, subcommand, None)
|
|
27
66
|
if command:
|
|
28
67
|
_args.pop(0)
|
|
68
|
+
if command_str == "help":
|
|
69
|
+
command = help
|
|
29
70
|
if not command:
|
|
30
71
|
command = getattr(commands, command_str, None)
|
|
31
72
|
if not callable(command):
|
|
32
73
|
raise CommandError(f"No such command: {command_str}")
|
|
33
74
|
# TODO: Use command signatures to provide argument validation and conversion.
|
|
34
|
-
if (command_str not in ["life", "next", "prev", "page"]) and not _args:
|
|
75
|
+
if (command_str not in ["life", "next", "prev", "page", "help"]) and not _args:
|
|
35
76
|
raise ArgumentError("No arguments")
|
|
36
77
|
if command_str in ["next", "prev"] and _args:
|
|
37
78
|
raise ArgumentError("No argument expected")
|
|
@@ -46,8 +87,11 @@ async def do_command(command_str: str, ctx: Context, *args):
|
|
|
46
87
|
console.print(*response)
|
|
47
88
|
else:
|
|
48
89
|
console.print(response)
|
|
49
|
-
except (ArgumentError, CommandError) as err:
|
|
50
|
-
|
|
90
|
+
except (ArgumentError, CommandError, LookupError) as err:
|
|
91
|
+
if commands.format == Format.rich:
|
|
92
|
+
console.print(Markdown(str(err)))
|
|
93
|
+
else:
|
|
94
|
+
console.print(err)
|
|
51
95
|
|
|
52
96
|
|
|
53
97
|
def get_context():
|
|
@@ -80,7 +124,7 @@ def write_history(histfile, histfile_size):
|
|
|
80
124
|
readline.write_history_file(histfile)
|
|
81
125
|
|
|
82
126
|
|
|
83
|
-
async def start_command_loop(ctx, histfile, histfile_size):
|
|
127
|
+
async def start_command_loop(commands, ctx, histfile, histfile_size):
|
|
84
128
|
try:
|
|
85
129
|
read_history(histfile)
|
|
86
130
|
|
|
@@ -97,7 +141,7 @@ async def start_command_loop(ctx, histfile, histfile_size):
|
|
|
97
141
|
args = _line.split(" ")
|
|
98
142
|
command = args[0]
|
|
99
143
|
args.remove(command)
|
|
100
|
-
await do_command(command, ctx, *args)
|
|
144
|
+
await do_command(commands, command, ctx, *args)
|
|
101
145
|
except (KeyboardInterrupt, EOFError):
|
|
102
146
|
write_history(histfile, histfile_size)
|
|
103
147
|
console.print()
|
|
@@ -106,14 +150,16 @@ async def start_command_loop(ctx, histfile, histfile_size):
|
|
|
106
150
|
async def start():
|
|
107
151
|
ctx = get_context()
|
|
108
152
|
|
|
153
|
+
loop = asyncio.get_running_loop()
|
|
154
|
+
commands = Commands(loop=loop, format=Format.rich)
|
|
109
155
|
if len(sys.argv) == 1:
|
|
110
156
|
ctx.per_page = 20
|
|
111
|
-
await start_command_loop(ctx, histfile, histfile_size)
|
|
157
|
+
await start_command_loop(commands, ctx, histfile, histfile_size)
|
|
112
158
|
else:
|
|
113
159
|
ctx.per_page = 0
|
|
114
160
|
command = sys.argv[1]
|
|
115
161
|
args = sys.argv[2:]
|
|
116
|
-
await do_command(command, ctx, *args)
|
|
162
|
+
await do_command(commands, command, ctx, *args)
|
|
117
163
|
|
|
118
164
|
|
|
119
165
|
def main():
|
|
@@ -6,7 +6,7 @@ exclude_dirs = ["tests"]
|
|
|
6
6
|
|
|
7
7
|
[tool.poetry]
|
|
8
8
|
name = "dronefly-cli"
|
|
9
|
-
version = "0.
|
|
9
|
+
version = "0.3.0.dev0"
|
|
10
10
|
description = "Dronefly command-line interface"
|
|
11
11
|
authors = ["Ben Armstrong <synrg@debian.org>"]
|
|
12
12
|
license = "AGPL-3.0-or-later"
|
|
@@ -15,7 +15,7 @@ readme = "README.md"
|
|
|
15
15
|
[tool.poetry.dependencies]
|
|
16
16
|
python = ">=3.11,<3.13"
|
|
17
17
|
pyreadline3 = "^3.4.1"
|
|
18
|
-
dronefly-core = "0.
|
|
18
|
+
dronefly-core = "0.5.0.dev0"
|
|
19
19
|
rich = "^13.2"
|
|
20
20
|
|
|
21
21
|
[tool.poetry.dev-dependencies]
|
|
File without changes
|
|
File without changes
|