replbase 0.0.2__tar.gz → 0.0.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: replbase
3
- Version: 0.0.2
3
+ Version: 0.0.4
4
4
  Summary: "Combination of other REPL tools into a reusable class that generates a REPL"
5
5
  License: MIT
6
6
  Author: Joseph Bochinski
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
4
4
 
5
5
  [tool.poetry]
6
6
  name = "replbase"
7
- version = "0.0.2"
7
+ version = "0.0.4"
8
8
  description = "\"Combination of other REPL tools into a reusable class that generates a REPL\""
9
9
  authors = [ "Joseph Bochinski <stirgejr@gmail.com>",]
10
10
  license = "MIT"
@@ -17,7 +17,7 @@ import argparse
17
17
  import os
18
18
  import shlex
19
19
 
20
- from dataclasses import dataclass
20
+ from dataclasses import dataclass, field
21
21
  from typing import Callable, Literal
22
22
 
23
23
  from prompt_toolkit import PromptSession
@@ -46,6 +46,8 @@ class ReplCommand:
46
46
  command: Callable = None
47
47
  help_txt: str = ""
48
48
  parser: argparse.ArgumentParser = None
49
+ def_args: list = field(default_factory=list)
50
+ def_kwargs: dict = field(default_factory=dict)
49
51
 
50
52
 
51
53
  @dataclass
@@ -194,6 +196,8 @@ class ReplBase:
194
196
  help_txt: str = "",
195
197
  use_parser: bool = False,
196
198
  description: str = "",
199
+ *def_args,
200
+ **def_kwargs,
197
201
  ) -> ReplCommand:
198
202
  """Add a command to the REPL
199
203
 
@@ -207,6 +211,8 @@ class ReplBase:
207
211
  to the new ReplCommand instance. Defaults to False.
208
212
  description (str, optional): Optional description for the
209
213
  ArgumentParser help text. Defaults to help_txt.
214
+ def_args: Default arguments for the command function
215
+ def_kwargs: Default keyword arguments for the command function
210
216
 
211
217
  Returns:
212
218
  ReplCommand: The new ReplCommand instance
@@ -217,6 +223,11 @@ class ReplBase:
217
223
  new_cmd.parser = argparse.ArgumentParser(
218
224
  description=description or help_txt
219
225
  )
226
+ if def_args:
227
+ new_cmd.def_args = def_args
228
+ if def_kwargs:
229
+ new_cmd.def_kwargs = def_kwargs
230
+
220
231
  self.commands[cmd_name] = new_cmd
221
232
  return new_cmd
222
233
 
@@ -292,7 +303,11 @@ class ReplBase:
292
303
 
293
304
  cmd.command(cmd.parser.parse_args(cmd_args))
294
305
  else:
295
- cmd.command(*cmd_args)
306
+ cmd_args = cmd_args or cmd.def_args
307
+ if cmd.def_kwargs:
308
+ cmd.command(*cmd_args, **cmd.def_kwargs)
309
+ else:
310
+ cmd.command(*cmd_args)
296
311
  else:
297
312
  self.print(
298
313
  "[bold yellow][WARNING]: No function provided for command[/bold yellow]"
File without changes
File without changes
File without changes