dronefly-cli 0.2.3__tar.gz → 0.2.5__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.
@@ -1,18 +1,15 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dronefly-cli
3
- Version: 0.2.3
3
+ Version: 0.2.5
4
4
  Summary: Dronefly command-line interface
5
5
  License: AGPL-3.0-or-later
6
6
  Author: Ben Armstrong
7
7
  Author-email: synrg@debian.org
8
- Requires-Python: >=3.8.1,<3.13
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
- Classifier: Programming Language :: Python :: 3.9
12
- Classifier: Programming Language :: Python :: 3.10
13
11
  Classifier: Programming Language :: Python :: 3.11
14
- Classifier: Programming Language :: Python :: 3.12
15
- Requires-Dist: dronefly-core (==0.3.8)
12
+ Requires-Dist: dronefly-core (==0.3.9)
16
13
  Requires-Dist: pyreadline3 (>=3.4.1,<4.0.0)
17
14
  Requires-Dist: rich (>=13.2,<14.0)
18
15
  Description-Content-Type: text/markdown
@@ -4,7 +4,7 @@ import sys
4
4
  import readline
5
5
 
6
6
  from dronefly.core import Commands, Format
7
- from dronefly.core.models.user import User
7
+ from dronefly.core.models import Config, User
8
8
  from dronefly.core.commands import ArgumentError, CommandError, Context
9
9
  from dronefly.core.constants import INAT_USER_DEFAULT_PARAMS
10
10
  from rich.console import Console
@@ -18,21 +18,29 @@ histfile_size = 1000
18
18
 
19
19
  def do_command(command_str: str, ctx: Context, *args):
20
20
  try:
21
- command = getattr(commands, command_str, None)
21
+ command = None
22
+ _args = [*args]
23
+ if len(_args) > 0:
24
+ subcommand = "_".join([command_str, _args[0]])
25
+ command = getattr(commands, subcommand, None)
26
+ if command:
27
+ _args.pop(0)
28
+ if not command:
29
+ command = getattr(commands, command_str, None)
22
30
  if not callable(command):
23
31
  raise CommandError(f"No such command: {command_str}")
24
32
  # TODO: Use command signatures to provide argument validation and conversion.
25
- if (command_str not in ["life", "next", "prev", "page"]) and not args:
33
+ if (command_str not in ["life", "next", "prev", "page"]) and not _args:
26
34
  raise ArgumentError("No arguments")
27
- if command_str in ["next", "prev"] and args:
35
+ if command_str in ["next", "prev"] and _args:
28
36
  raise ArgumentError("No argument expected")
29
- if command_str in ["page"] and len(args) > 1:
37
+ if command_str in ["page"] and len(_args) > 1:
30
38
  raise ArgumentError("Too many arguments")
31
39
  # Argument conversion, if necessary:
32
- if command_str in ["page", "sel"] and len(args):
33
- response = command(ctx, int(args[0]))
40
+ if command_str in ["page", "sel"] and len(_args):
41
+ response = command(ctx, int(_args[0]))
34
42
  else:
35
- response = command(ctx, *args)
43
+ response = command(ctx, *_args)
36
44
  if isinstance(response, list):
37
45
  console.print(*response)
38
46
  else:
@@ -42,11 +50,20 @@ def do_command(command_str: str, ctx: Context, *args):
42
50
 
43
51
 
44
52
  def get_context():
45
- user_params = {"id": 1}
53
+ default_user_id = 1
54
+ config = Config()
55
+ user_config = config.user(default_user_id)
56
+ user_params = {"id": default_user_id}
46
57
  for param in ("inat_user_id", *INAT_USER_DEFAULT_PARAMS):
47
- param_env = os.environ.get(param.upper())
48
- if param_env:
49
- user_params[param] = int(param_env) if param_env.isnumeric() else param_env
58
+ param_value = None
59
+ if user_config:
60
+ param_value = user_config.get(param)
61
+ if not param_value:
62
+ param_value = os.environ.get(param.upper())
63
+ if param_value and param_value.isnumeric():
64
+ param_value = int(param_value)
65
+ if param_value:
66
+ user_params[param] = param_value
50
67
  user = User(**user_params)
51
68
  ctx = Context(author=user)
52
69
  return ctx
@@ -6,16 +6,16 @@ exclude_dirs = ["tests"]
6
6
 
7
7
  [tool.poetry]
8
8
  name = "dronefly-cli"
9
- version = "0.2.3"
9
+ version = "0.2.5"
10
10
  description = "Dronefly command-line interface"
11
11
  authors = ["Ben Armstrong <synrg@debian.org>"]
12
12
  license = "AGPL-3.0-or-later"
13
13
  readme = "README.md"
14
14
 
15
15
  [tool.poetry.dependencies]
16
- python = ">=3.8.1,<3.13"
16
+ python = ">=3.11,<3.13"
17
17
  pyreadline3 = "^3.4.1"
18
- dronefly-core = "0.3.8"
18
+ dronefly-core = "0.3.9"
19
19
  rich = "^13.2"
20
20
 
21
21
  [tool.poetry.dev-dependencies]
File without changes
File without changes