argenta 0.3.9__tar.gz → 0.4.0__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,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: argenta
3
- Version: 0.3.9
3
+ Version: 0.4.0
4
4
  Summary: python library for creating custom shells
5
5
  License: MIT
6
6
  Author: kolo
@@ -75,12 +75,11 @@ from argenta.command.flag import FlagsGroup, Flag
75
75
 
76
76
  router = Router()
77
77
 
78
- registered_flags = FlagsGroup([
78
+ registered_flags = FlagsGroup(
79
79
  Flag(flag_name='host',
80
80
  flag_prefix='--',
81
81
  possible_flag_values=re.compile(r'^192.168.\d{1,3}.\d{1,3}$')),
82
- Flag('port', '---', re.compile(r'^[0-9]{1,4}$'))
83
- ])
82
+ Flag('port', '--', re.compile(r'^[0-9]{1,4}$')))
84
83
 
85
84
 
86
85
  @router.command(Command("hello"))
@@ -380,8 +379,7 @@ Command(trigger: str,
380
379
  ```python
381
380
  Flag(flag_name: str,
382
381
  flag_prefix: typing.Literal['-', '--', '---'] = '-',
383
- ignore_flag_value_register: bool = False,
384
- possible_flag_values: list[str] | typing.Pattern[str] = False)
382
+ possible_flag_values: list[str] | typing.Pattern[str] | False = True)
385
383
  ```
386
384
 
387
385
  ---
@@ -390,9 +388,10 @@ Flag(flag_name: str,
390
388
  - **name : mean**
391
389
  - `flag_name` (`str`): Имя флага
392
390
  - `flag_prefix` (`Literal['-', '--', '---']`): Префикс команды, допустимым значением является от одного до трёх минусов
393
- - `ignore_flag_value_register` (`bool`): Будет ли игнорироваться регистр значения введённого флага
394
- - `possible_flag_values` (`list[str] | Pattern[str]`): Множество допустимых значений флага, может быть задано
395
- списком с допустимыми значениями или регулярным выражением (рекомендуется `re.compile(r'example exspression')`)
391
+ - `possible_flag_values` (`list[str] | Pattern[str] | bool`): Множество допустимых значений флага, может быть задано
392
+ списком с допустимыми значениями или регулярным выражением (рекомендуется `re.compile(r'example exspression')`), при значении
393
+ аргумента `False` у введённого флага не может быть значения, иначе будет вызвано исключение и обработано соответствующим
394
+ еррор-хэндлером
396
395
 
397
396
  ---
398
397
 
@@ -425,14 +424,14 @@ Flag(flag_name: str,
425
424
 
426
425
  ### Конструктор
427
426
  ```python
428
- FlagsGroup(flags: list[Flag] = None)
427
+ FlagsGroup(*flagы: Flag)
429
428
  ```
430
429
 
431
430
  ---
432
431
 
433
432
  **Аргументы:**
434
433
  - **name : mean**
435
- - `flags` (`list[Flag]`): Список флагов, которые будут объединены в одну группу
434
+ - `*flags` (`Flag`): Неограниченное количество передаваемых флагов
436
435
 
437
436
  ---
438
437
 
@@ -60,12 +60,11 @@ from argenta.command.flag import FlagsGroup, Flag
60
60
 
61
61
  router = Router()
62
62
 
63
- registered_flags = FlagsGroup([
63
+ registered_flags = FlagsGroup(
64
64
  Flag(flag_name='host',
65
65
  flag_prefix='--',
66
66
  possible_flag_values=re.compile(r'^192.168.\d{1,3}.\d{1,3}$')),
67
- Flag('port', '---', re.compile(r'^[0-9]{1,4}$'))
68
- ])
67
+ Flag('port', '--', re.compile(r'^[0-9]{1,4}$')))
69
68
 
70
69
 
71
70
  @router.command(Command("hello"))
@@ -365,8 +364,7 @@ Command(trigger: str,
365
364
  ```python
366
365
  Flag(flag_name: str,
367
366
  flag_prefix: typing.Literal['-', '--', '---'] = '-',
368
- ignore_flag_value_register: bool = False,
369
- possible_flag_values: list[str] | typing.Pattern[str] = False)
367
+ possible_flag_values: list[str] | typing.Pattern[str] | False = True)
370
368
  ```
371
369
 
372
370
  ---
@@ -375,9 +373,10 @@ Flag(flag_name: str,
375
373
  - **name : mean**
376
374
  - `flag_name` (`str`): Имя флага
377
375
  - `flag_prefix` (`Literal['-', '--', '---']`): Префикс команды, допустимым значением является от одного до трёх минусов
378
- - `ignore_flag_value_register` (`bool`): Будет ли игнорироваться регистр значения введённого флага
379
- - `possible_flag_values` (`list[str] | Pattern[str]`): Множество допустимых значений флага, может быть задано
380
- списком с допустимыми значениями или регулярным выражением (рекомендуется `re.compile(r'example exspression')`)
376
+ - `possible_flag_values` (`list[str] | Pattern[str] | bool`): Множество допустимых значений флага, может быть задано
377
+ списком с допустимыми значениями или регулярным выражением (рекомендуется `re.compile(r'example exspression')`), при значении
378
+ аргумента `False` у введённого флага не может быть значения, иначе будет вызвано исключение и обработано соответствующим
379
+ еррор-хэндлером
381
380
 
382
381
  ---
383
382
 
@@ -410,14 +409,14 @@ Flag(flag_name: str,
410
409
 
411
410
  ### Конструктор
412
411
  ```python
413
- FlagsGroup(flags: list[Flag] = None)
412
+ FlagsGroup(*flagы: Flag)
414
413
  ```
415
414
 
416
415
  ---
417
416
 
418
417
  **Аргументы:**
419
418
  - **name : mean**
420
- - `flags` (`list[Flag]`): Список флагов, которые будут объединены в одну группу
419
+ - `*flags` (`Flag`): Неограниченное количество передаваемых флагов
421
420
 
422
421
  ---
423
422
 
@@ -1,4 +1,3 @@
1
- from pprint import pprint
2
1
  from typing import Callable
3
2
  from inspect import getfullargspec
4
3
  import re
@@ -51,7 +50,7 @@ class App:
51
50
  self._invalid_input_flags_handler: Callable[[str], None] = lambda raw_command: print_func(f'Incorrect flag syntax: "{raw_command}"')
52
51
  self._repeated_input_flags_handler: Callable[[str], None] = lambda raw_command: print_func(f'Repeated input flags: "{raw_command}"')
53
52
  self._empty_input_command_handler: Callable[[], None] = lambda: print_func(f'Empty input command')
54
- self._unknown_command_handler: Callable[[Command], None] = lambda command: print_func(f"Unknown command: {command.get_string_entity()}")
53
+ self._unknown_command_handler: Callable[[Command], None] = lambda command: print_func(f"Unknown command: {command.get_trigger()}")
55
54
 
56
55
 
57
56
  def start_polling(self) -> None:
@@ -101,7 +100,9 @@ class App:
101
100
  self.print_func(self.prompt)
102
101
  continue
103
102
 
104
- self._check_command_for_exit_command(input_command.get_trigger())
103
+ is_exit = self._is_exit_command(input_command.get_trigger())
104
+ if is_exit:
105
+ return
105
106
 
106
107
  self.print_func(self.line_separate)
107
108
  is_unknown_command: bool = self._check_is_command_unknown(input_command)
@@ -213,15 +214,16 @@ class App:
213
214
  raise RepeatedCommandInDifferentRoutersException()
214
215
 
215
216
 
216
- def _check_command_for_exit_command(self, command: str):
217
+ def _is_exit_command(self, command: str):
217
218
  if command.lower() == self.exit_command.lower():
218
219
  if self.ignore_exit_command_register:
219
220
  self.print_func(self.farewell_message)
220
- exit(0)
221
+ return True
221
222
  else:
222
223
  if command == self.exit_command:
223
224
  self.print_func(self.farewell_message)
224
- exit(0)
225
+ return True
226
+ return False
225
227
 
226
228
 
227
229
  def _check_is_command_unknown(self, command: Command):
@@ -6,6 +6,7 @@ from .exceptions import (UnprocessedInputFlagException,
6
6
 
7
7
  from typing import Generic, TypeVar, cast, Literal
8
8
 
9
+
9
10
  CommandType = TypeVar('CommandType')
10
11
 
11
12
 
@@ -15,8 +16,7 @@ class Command(Generic[CommandType]):
15
16
  flags: Flag | FlagsGroup = None):
16
17
  self._trigger = trigger
17
18
  self._description = f'description for "{self._trigger}" command' if not description else description
18
- self._registered_flags: FlagsGroup | None = flags if isinstance(flags, FlagsGroup) else FlagsGroup([flags]) if isinstance(flags, Flag) else flags
19
-
19
+ self._registered_flags: FlagsGroup | None = flags if isinstance(flags, FlagsGroup) else FlagsGroup(flags) if isinstance(flags, Flag) else flags
20
20
  self._input_flags: FlagsGroup | None = None
21
21
 
22
22
 
@@ -56,7 +56,7 @@ class Command(Generic[CommandType]):
56
56
  return self._input_flags
57
57
 
58
58
  @staticmethod
59
- def parse_input_command(raw_command: str) -> 'Command[CommandType]':
59
+ def parse_input_command(raw_command: str) -> CommandType:
60
60
  if not raw_command:
61
61
  raise EmptyInputCommandException()
62
62
  list_of_tokens = raw_command.split()
@@ -0,0 +1,21 @@
1
+ from dataclasses import dataclass
2
+ from argenta.command.flag import Flag
3
+ import re
4
+
5
+
6
+ @dataclass
7
+ class DefaultFlags:
8
+ help_flag = Flag(flag_name='help', possible_flag_values=False)
9
+ short_help_flag = Flag(flag_name='h', flag_prefix='-', possible_flag_values=False)
10
+
11
+ info_flag = Flag(flag_name='info', possible_flag_values=False)
12
+ short_info_flag = Flag(flag_name='i', flag_prefix='-', possible_flag_values=False)
13
+
14
+ all_flag = Flag(flag_name='all', possible_flag_values=False)
15
+ short_all_flag = Flag(flag_name='a', flag_prefix='-', possible_flag_values=False)
16
+
17
+ host_flag = Flag(flag_name='host', possible_flag_values=re.compile(r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$'))
18
+ short_host_flag = Flag(flag_name='h', flag_prefix='-', possible_flag_values=re.compile(r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$'))
19
+
20
+ port_flag = Flag(flag_name='port', possible_flag_values=re.compile(r'^\d{1,5}$'))
21
+ short_port_flag = Flag(flag_name='p', flag_prefix='-', possible_flag_values=re.compile(r'^\d{1,5}$'))
@@ -1,4 +1,4 @@
1
- from argenta.command.flag.entity import Flag
1
+ from argenta.command.flag import Flag
2
2
 
3
3
 
4
4
  class FlagsGroup:
@@ -23,7 +23,7 @@ class Router:
23
23
  self._command_entities: list[dict[str, Callable[[], None] | Command]] = []
24
24
  self._ignore_command_register: bool = False
25
25
 
26
- self._not_valid_flag_handler: Callable[[Flag], None] = lambda flag: print(f"Undefined or incorrect input flag: '{flag.get_string_entity()} {flag.get_value()}'")
26
+ self._not_valid_flag_handler: Callable[[Flag], None] = lambda flag: print(f"Undefined or incorrect input flag: {flag.get_string_entity()}{(' '+flag.get_value()) if flag.get_value() else ''}")
27
27
 
28
28
 
29
29
  def command(self, command: Command) -> Callable[[Any], Any]:
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "argenta"
3
- version = "0.3.9"
3
+ version = "0.4.0"
4
4
  description = "python library for creating custom shells"
5
5
  authors = [
6
6
  {name = "kolo", email = "kolo.is.main@gmail.com"}
@@ -1,18 +0,0 @@
1
- from argenta.command.flag import Flag
2
- import re
3
-
4
-
5
- help_flag = Flag(flag_name='help', possible_flag_values=False)
6
- short_help_flag = Flag(flag_name='h', flag_prefix='-', possible_flag_values=False)
7
-
8
- info_flag = Flag(flag_name='info', possible_flag_values=False)
9
- short_info_flag = Flag(flag_name='i', flag_prefix='-', possible_flag_values=False)
10
-
11
- all_flag = Flag(flag_name='all', possible_flag_values=False)
12
- short_all_flag = Flag(flag_name='a', flag_prefix='-', possible_flag_values=False)
13
-
14
- host_flag = Flag(flag_name='host', possible_flag_values=re.compile(r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$'))
15
- short_host_flag = Flag(flag_name='h', flag_prefix='-', possible_flag_values=re.compile(r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$'))
16
-
17
- port_flag = Flag(flag_name='port', possible_flag_values=re.compile(r'^\d{1,5}$'))
18
- short_port_flag = Flag(flag_name='p', flag_prefix='-', possible_flag_values=re.compile(r'^\d{1,5}$'))
File without changes
File without changes
File without changes