argenta 0.5.0b0__py3-none-any.whl → 1.0.0__py3-none-any.whl

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.
Files changed (36) hide show
  1. argenta/app/autocompleter/entity.py +57 -13
  2. argenta/app/defaults.py +7 -4
  3. argenta/app/dividing_line/models.py +55 -13
  4. argenta/app/models.py +376 -178
  5. argenta/app/registered_routers/entity.py +20 -7
  6. argenta/command/__init__.py +1 -1
  7. argenta/command/exceptions.py +22 -3
  8. argenta/command/flag/__init__.py +2 -2
  9. argenta/command/flag/defaults.py +21 -11
  10. argenta/command/flag/models.py +73 -92
  11. argenta/command/flags/__init__.py +16 -0
  12. argenta/command/flags/models.py +90 -0
  13. argenta/command/models.py +124 -39
  14. argenta/orchestrator/__init__.py +4 -0
  15. argenta/orchestrator/argparser/__init__.py +4 -0
  16. argenta/orchestrator/argparser/arguments/__init__.py +8 -0
  17. argenta/orchestrator/argparser/arguments/models.py +56 -0
  18. argenta/orchestrator/argparser/entity.py +59 -0
  19. argenta/orchestrator/entity.py +35 -0
  20. argenta/response/__init__.py +5 -0
  21. argenta/response/entity.py +29 -0
  22. argenta/response/status.py +8 -0
  23. argenta/router/__init__.py +1 -1
  24. argenta/router/command_handler/entity.py +57 -11
  25. argenta/router/defaults.py +1 -2
  26. argenta/router/entity.py +181 -92
  27. argenta/router/exceptions.py +17 -6
  28. argenta-1.0.0.dist-info/METADATA +70 -0
  29. argenta-1.0.0.dist-info/RECORD +37 -0
  30. {argenta-0.5.0b0.dist-info → argenta-1.0.0.dist-info}/WHEEL +1 -1
  31. argenta/app/exceptions.py +0 -15
  32. argenta/router/command_handlers/__init__.py +0 -0
  33. argenta/router/command_handlers/entity.py +0 -21
  34. argenta-0.5.0b0.dist-info/METADATA +0 -603
  35. argenta-0.5.0b0.dist-info/RECORD +0 -29
  36. {argenta-0.5.0b0.dist-info → argenta-1.0.0.dist-info/licenses}/LICENSE +0 -0
@@ -1,24 +1,44 @@
1
1
  import os
2
2
  import readline
3
+ from typing import Never
3
4
 
4
5
 
5
6
  class AutoCompleter:
6
- def __init__(self, history_filename: str = False, autocomplete_button: str = 'tab'):
7
+ def __init__(
8
+ self, history_filename: str = False, autocomplete_button: str = "tab"
9
+ ) -> None:
10
+ """
11
+ Public. Configures and implements auto-completion of input command
12
+ :param history_filename: the name of the file for saving the history of the autocompleter
13
+ :param autocomplete_button: the button for auto-completion
14
+ :return: None
15
+ """
7
16
  self.history_filename = history_filename
8
17
  self.autocomplete_button = autocomplete_button
9
- self.matches = []
10
18
 
11
- def complete(self, text, state):
12
- matches = sorted(cmd for cmd in self.get_history_items() if cmd.startswith(text))
19
+ def _complete(self, text, state) -> str | None:
20
+ """
21
+ Private. Auto-completion function
22
+ :param text: part of the command being entered
23
+ :param state: the current cursor position is relative to the beginning of the line
24
+ :return: the desired candidate as str or None
25
+ """
26
+ matches: list[str] = sorted(
27
+ cmd for cmd in self.get_history_items() if cmd.startswith(text)
28
+ )
13
29
  if len(matches) > 1:
14
30
  common_prefix = matches[0]
15
31
  for match in matches[1:]:
16
32
  i = 0
17
- while i < len(common_prefix) and i < len(match) and common_prefix[i] == match[i]:
33
+ while (
34
+ i < len(common_prefix)
35
+ and i < len(match)
36
+ and common_prefix[i] == match[i]
37
+ ):
18
38
  i += 1
19
39
  common_prefix = common_prefix[:i]
20
40
  if state == 0:
21
- readline.insert_text(common_prefix[len(text):])
41
+ readline.insert_text(common_prefix[len(text) :])
22
42
  readline.redisplay()
23
43
  return None
24
44
  elif len(matches) == 1:
@@ -26,7 +46,12 @@ class AutoCompleter:
26
46
  else:
27
47
  return None
28
48
 
29
- def initial_setup(self, all_commands: list[str]):
49
+ def initial_setup(self, all_commands: list[str]) -> None:
50
+ """
51
+ Private. Initial setup function
52
+ :param all_commands: Registered commands for adding them to the autocomplete history
53
+ :return: None
54
+ """
30
55
  if self.history_filename:
31
56
  if os.path.exists(self.history_filename):
32
57
  readline.read_history_file(self.history_filename)
@@ -34,14 +59,33 @@ class AutoCompleter:
34
59
  for line in all_commands:
35
60
  readline.add_history(line)
36
61
 
37
- readline.set_completer(self.complete)
38
- readline.set_completer_delims(readline.get_completer_delims().replace(' ', ''))
39
- readline.parse_and_bind(f'{self.autocomplete_button}: complete')
62
+ readline.set_completer(self._complete)
63
+ readline.set_completer_delims(readline.get_completer_delims().replace(" ", ""))
64
+ readline.parse_and_bind(f"{self.autocomplete_button}: complete")
40
65
 
41
- def exit_setup(self):
66
+ def exit_setup(self, all_commands: list[str]) -> None:
67
+ """
68
+ Private. Exit setup function
69
+ :return: None
70
+ """
42
71
  if self.history_filename:
43
72
  readline.write_history_file(self.history_filename)
73
+ with open(self.history_filename, "r") as history_file:
74
+ raw_history = history_file.read()
75
+ pretty_history: list[str] = []
76
+ for line in set(raw_history.strip().split("\n")):
77
+ if line.split()[0] in all_commands:
78
+ pretty_history.append(line)
79
+ with open(self.history_filename, "w") as history_file:
80
+ history_file.write("\n".join(pretty_history))
44
81
 
45
82
  @staticmethod
46
- def get_history_items():
47
- return [readline.get_history_item(i) for i in range(1, readline.get_current_history_length() + 1)]
83
+ def get_history_items() -> list[str] | list[Never]:
84
+ """
85
+ Private. Returns a list of all commands entered by the user
86
+ :return: all commands entered by the user as list[str] | list[Never]
87
+ """
88
+ return [
89
+ readline.get_history_item(i)
90
+ for i in range(1, readline.get_current_history_length() + 1)
91
+ ]
argenta/app/defaults.py CHANGED
@@ -2,8 +2,11 @@ from dataclasses import dataclass
2
2
 
3
3
 
4
4
  @dataclass
5
- class PredeterminedMessages:
6
- USAGE = '[b dim]Usage[/b dim]: [i]<command> <[green]flags[/green]>[/i]'
7
- HELP = '[b dim]Help[/b dim]: [i]<command>[/i] [b red]--help[/b red]'
8
- AUTOCOMPLETE = '[b dim]Autocomplete[/b dim]: [i]<part>[/i] [bold]<tab>'
5
+ class PredefinedMessages:
6
+ """
7
+ Public. A dataclass with predetermined messages for quick use
8
+ """
9
9
 
10
+ USAGE = "[b dim]Usage[/b dim]: [i]<command> <[green]flags[/green]>[/i]"
11
+ HELP = "[b dim]Help[/b dim]: [i]<command>[/i] [b red]--help[/b red]"
12
+ AUTOCOMPLETE = "[b dim]Autocomplete[/b dim]: [i]<part>[/i] [bold]<tab>"
@@ -1,24 +1,66 @@
1
- class BaseDividingLine:
2
- def __init__(self, unit_part: str = '-'):
3
- self.unit_part = unit_part
1
+ from abc import ABC
4
2
 
5
- def get_unit_part(self):
6
- if len(self.unit_part) == 0:
7
- return ' '
3
+
4
+ class BaseDividingLine(ABC):
5
+ def __init__(self, unit_part: str = "-") -> None:
6
+ """
7
+ Private. The basic dividing line
8
+ :param unit_part: the single part of the dividing line
9
+ :return: None
10
+ """
11
+ self._unit_part = unit_part
12
+
13
+ def get_unit_part(self) -> str:
14
+ """
15
+ Private. Returns the unit part of the dividing line
16
+ :return: unit_part of dividing line as str
17
+ """
18
+ if len(self._unit_part) == 0:
19
+ return " "
8
20
  else:
9
- return self.unit_part[0]
21
+ return self._unit_part[0]
22
+
10
23
 
11
24
  class StaticDividingLine(BaseDividingLine):
12
- def __init__(self, unit_part: str = '-', length: int = 25):
25
+ def __init__(self, unit_part: str = "-", length: int = 25) -> None:
26
+ """
27
+ Public. The static dividing line
28
+ :param unit_part: the single part of the dividing line
29
+ :param length: the length of the dividing line
30
+ :return: None
31
+ """
13
32
  super().__init__(unit_part)
14
33
  self.length = length
15
34
 
16
- def get_full_line(self):
17
- return f'\n[dim]{self.length * self.get_unit_part()}[/dim]\n'
35
+ def get_full_static_line(self, is_override: bool) -> str:
36
+ """
37
+ Private. Returns the full line of the dividing line
38
+ :param is_override: has the default text layout been redefined
39
+ :return: full line of dividing line as str
40
+ """
41
+ if is_override:
42
+ return f"\n{self.length * self.get_unit_part()}\n"
43
+ else:
44
+ return f"\n[dim]{self.length * self.get_unit_part()}[/dim]\n"
18
45
 
19
46
 
20
47
  class DynamicDividingLine(BaseDividingLine):
21
- def get_full_line(self, length: int):
22
- return f'\n[dim]{self.get_unit_part() * length}[/dim]\n'
23
-
48
+ def __init__(self, unit_part: str = "-") -> None:
49
+ """
50
+ Public. The dynamic dividing line
51
+ :param unit_part: the single part of the dividing line
52
+ :return: None
53
+ """
54
+ super().__init__(unit_part)
24
55
 
56
+ def get_full_dynamic_line(self, length: int, is_override: bool) -> str:
57
+ """
58
+ Private. Returns the full line of the dividing line
59
+ :param length: the length of the dividing line
60
+ :param is_override: has the default text layout been redefined
61
+ :return: full line of dividing line as str
62
+ """
63
+ if is_override:
64
+ return f"\n{length * self.get_unit_part()}\n"
65
+ else:
66
+ return f"\n[dim]{self.get_unit_part() * length}[/dim]\n"