termkit 0.2.3__tar.gz → 0.2.4__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.1
2
2
  Name: termkit
3
- Version: 0.2.3
3
+ Version: 0.2.4
4
4
  Summary: Python command line application framework
5
5
  License: MIT
6
6
  Author: Thomas Mahé
@@ -3,7 +3,7 @@
3
3
 
4
4
  [tool.poetry]
5
5
  name = "termkit"
6
- version = "0.2.3"
6
+ version = "0.2.4"
7
7
  description = "Python command line application framework"
8
8
  authors = ["Thomas Mahé <contact@tmahe.dev>"]
9
9
  license = "MIT"
@@ -9,7 +9,7 @@ package_data = \
9
9
 
10
10
  setup_kwargs = {
11
11
  'name': 'termkit',
12
- 'version': '0.2.3',
12
+ 'version': '0.2.4',
13
13
  'description': 'Python command line application framework',
14
14
  'long_description': '<p align="center">\n <img alt="Termkit" title="Termkit" src="docs/images/banner.png#gh-dark-mode-only" width="450">\n <img alt="Termkit" title="Termkit" src="docs/images/banner_light.png#gh-light-mode-only" width="450">\n</p>\n<div align="center">\n <b><i>Command Line Tools with... ease.</i></b>\n<hr>\n\n</div>\n\n## Introduction\n\nTermkit is a Python framework designed for building command line interface applications using functions \nand type hints [[PEP 484]](https://peps.python.org/pep-0484/). \n**Solely written using [Python Standard Library](https://docs.python.org/3/library/)** and will always be to ensure\nminimal dependency footprint within your project.\n\n## Features\n\n- Build CLI Tools from functional code\n- Create fast prototypes using implicit arguments\n- Compatible with [argcomplete](https://pypi.org/project/argcomplete/) for autocompletion\n\n## Usage\n\nTo get started, follow these steps:\n\n#### 1. Install Termkit using pip\n```shell\n$ pip install termkit\n```\n#### 2. Test it with given example\n\n```python\n# app.py\nfrom termkit import Termkit\n\napp = Termkit()\n\n@app.command()\ndef greet(name, count=2):\n for _ in range(count):\n print(name)\n\nif __name__ == "__main__":\n app()\n\n```\n```shell\n$ python3 ./app.py "Hello Termkit" --count 3\nHello Termkit\nHello Termkit\nHello Termkit\n```\n\n\n## Work in Progress Disclaimer\n\n🛠️ **Please Note: This documentation is a work in progress.** 🛠️\n\nTermkit is constantly evolving, and we are actively working on expanding and improving this documentation. Some sections may be incomplete or subject to change. We appreciate your patience and understanding as we continue to enhance this resource.\n\nIf you have any questions or encounter any issues while using Termkit, please feel free to reach me at [contact@tmahe.dev](mailto:contact@tmahe.dev).\n\nThank you for being a part of Termkit journey! 🌟\n',
15
15
  'author': 'Thomas Mahé',
@@ -12,7 +12,7 @@ from termkit.groups import _TermkitGroup, get_parser_from_group
12
12
 
13
13
 
14
14
  class _TermkitArgument:
15
- _ignored_params = ["flags", "group"]
15
+ _ignored_params = ["flags", "group", "help"]
16
16
 
17
17
  @abstractmethod
18
18
  def _populate(self, parser: argparse.ArgumentParser, dest: str, help: str):
@@ -34,11 +34,13 @@ class Positional(_TermkitArgument):
34
34
  metavar: Optional[str] = None,
35
35
  nargs: Optional[typing.Union[int, str]] = None,
36
36
  choices: Optional[typing.Container] = None,
37
+ help: Optional[str] = None,
37
38
  ):
38
39
  self.type = type
39
40
  self.metavar = metavar
40
41
  self.nargs = nargs
41
42
  self.choices = choices
43
+ self.help = help
42
44
 
43
45
  def _populate(self, parser: argparse.ArgumentParser, dest: str, help: str):
44
46
  parser.add_argument(dest, **self.argparse_params, help=help)
@@ -55,6 +57,7 @@ class Option(_TermkitArgument):
55
57
  group: Optional[_TermkitGroup] = None,
56
58
  nargs: Optional[typing.Union[int, str]] = None,
57
59
  choices: Optional[typing.Container] = None,
60
+ help: Optional[str] = None,
58
61
  ):
59
62
  self.flags = flags
60
63
  self.type = type
@@ -64,24 +67,27 @@ class Option(_TermkitArgument):
64
67
  self.default = default
65
68
  self.group = group
66
69
  self.choices = choices
70
+ self.help = help
67
71
 
68
72
  def _populate(self, parser: argparse.ArgumentParser, dest: str, help: str):
69
73
  parser = get_parser_from_group(parser, self.group)
70
- parser.add_argument(*self.flags, **self.argparse_params, dest=dest, help=help)
74
+ parser.add_argument(*sorted(self.flags, key=len), **self.argparse_params, dest=dest, help=help)
71
75
 
72
76
 
73
77
  class Flag(_TermkitArgument):
74
- _ignored_params = ["flags", "type", "group"]
78
+ _ignored_params = ["flags", "type", "group", "help"]
75
79
 
76
80
  def __init__(
77
81
  self,
78
82
  *flags: str,
79
83
  store: Optional[typing.Any] = True,
80
84
  group: Optional[_TermkitGroup] = None,
85
+ help: Optional[str] = None,
81
86
  ):
82
87
  self.flags = flags
83
88
  self.type = None
84
89
  self.group = group
90
+ self.help = help
85
91
  if store is True:
86
92
  self.action = "store_true"
87
93
  if store is False:
@@ -92,4 +98,4 @@ class Flag(_TermkitArgument):
92
98
 
93
99
  def _populate(self, parser: argparse.ArgumentParser, dest: str, help: str):
94
100
  parser = get_parser_from_group(parser, self.group)
95
- parser.add_argument(*self.flags, **self.argparse_params, dest=dest, help=help)
101
+ parser.add_argument(*sorted(self.flags, key=len), **self.argparse_params, dest=dest, help=help)
@@ -16,11 +16,14 @@ __BUILTIN_TYPES__ = [str, int, float, complex, bool]
16
16
 
17
17
  class TermkitParser(argparse.ArgumentParser):
18
18
  def __init__(self, *args, **kwargs):
19
- super().__init__(*args, **kwargs)
19
+ super().__init__(*args, **kwargs, add_help=False)
20
20
 
21
21
  self._optionals.title = "Options"
22
22
  self._positionals.title = "Positionals"
23
23
 
24
+ self.add_argument('-h', '--help', action='help', default=argparse.SUPPRESS,
25
+ help='Show this help message and exit')
26
+
24
27
  if kwargs.get("formatter_class", None) is None:
25
28
  self.formatter_class = TermkitDefaultFormatter
26
29
 
@@ -56,6 +59,7 @@ class ArgumentHandler:
56
59
  elif typing.get_origin(param.annotation) is typing.Annotated:
57
60
  _type, option = typing.get_args(param.annotation)
58
61
  if isinstance(option, _TermkitArgument):
62
+ param_help = option.help if option.help is not None else param_help
59
63
  option._populate(self.parser, dest=param_name, help=param_help)
60
64
 
61
65
  # f(param : <annotation> = <default>)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes