replbase 0.0.10__tar.gz → 0.0.13__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.
- {replbase-0.0.10 → replbase-0.0.13}/PKG-INFO +1 -1
- {replbase-0.0.10 → replbase-0.0.13}/pyproject.toml +1 -1
- {replbase-0.0.10 → replbase-0.0.13}/replbase/repl_base.py +19 -11
- {replbase-0.0.10 → replbase-0.0.13}/LICENSE +0 -0
- {replbase-0.0.10 → replbase-0.0.13}/README.md +0 -0
- {replbase-0.0.10 → replbase-0.0.13}/replbase/__init__.py +0 -0
|
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
|
|
|
4
4
|
|
|
5
5
|
[tool.poetry]
|
|
6
6
|
name = "replbase"
|
|
7
|
-
version = "0.0.
|
|
7
|
+
version = "0.0.13"
|
|
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"
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"""
|
|
13
13
|
|
|
14
14
|
# region Imports
|
|
15
|
+
from __future__ import annotations
|
|
15
16
|
|
|
16
17
|
import argparse
|
|
17
18
|
import os
|
|
@@ -51,7 +52,6 @@ class ReplCommand:
|
|
|
51
52
|
command: Callable = None
|
|
52
53
|
help_txt: str = ""
|
|
53
54
|
parser: argparse.ArgumentParser = None
|
|
54
|
-
def_args: list = field(default_factory=list)
|
|
55
55
|
def_kwargs: dict = field(default_factory=dict)
|
|
56
56
|
|
|
57
57
|
|
|
@@ -94,6 +94,8 @@ class ReplBase:
|
|
|
94
94
|
"""Command dictionary for prompt_toolkit. Keys are command names,
|
|
95
95
|
values are the corresponding description/help text"""
|
|
96
96
|
|
|
97
|
+
parent: ReplBase = None
|
|
98
|
+
|
|
97
99
|
def __post_init__(self) -> None:
|
|
98
100
|
if isinstance(self.commands, dict):
|
|
99
101
|
for cmd_name, cmd in self.commands.items():
|
|
@@ -228,7 +230,6 @@ class ReplBase:
|
|
|
228
230
|
def add_command(
|
|
229
231
|
self,
|
|
230
232
|
cmd_name: str,
|
|
231
|
-
*def_args,
|
|
232
233
|
cmd_func: Callable = None,
|
|
233
234
|
help_txt: str = "",
|
|
234
235
|
use_parser: bool = False,
|
|
@@ -259,8 +260,6 @@ class ReplBase:
|
|
|
259
260
|
new_cmd.parser = argparse.ArgumentParser(
|
|
260
261
|
description=description or help_txt
|
|
261
262
|
)
|
|
262
|
-
if def_args:
|
|
263
|
-
new_cmd.def_args = def_args
|
|
264
263
|
if def_kwargs:
|
|
265
264
|
new_cmd.def_kwargs = def_kwargs
|
|
266
265
|
|
|
@@ -281,6 +280,15 @@ class ReplBase:
|
|
|
281
280
|
f"[bold green]{cmd_name}:[/bold green] [cyan]{cmd.help_txt}[/cyan]"
|
|
282
281
|
)
|
|
283
282
|
|
|
283
|
+
def print_prompt(self) -> None:
|
|
284
|
+
"""Prints the prompt message if defined"""
|
|
285
|
+
|
|
286
|
+
if isinstance(self.init_prompt, list):
|
|
287
|
+
for line in self.init_prompt:
|
|
288
|
+
self.print(line)
|
|
289
|
+
else:
|
|
290
|
+
self.print(self.init_prompt)
|
|
291
|
+
|
|
284
292
|
def run(self) -> None:
|
|
285
293
|
"""Initiates a REPL with the provided configuration"""
|
|
286
294
|
|
|
@@ -295,11 +303,7 @@ class ReplBase:
|
|
|
295
303
|
tempfile=self.temp_file,
|
|
296
304
|
)
|
|
297
305
|
|
|
298
|
-
|
|
299
|
-
for line in self.init_prompt:
|
|
300
|
-
self.print(line)
|
|
301
|
-
else:
|
|
302
|
-
self.print(self.init_prompt)
|
|
306
|
+
self.print_prompt()
|
|
303
307
|
|
|
304
308
|
while True:
|
|
305
309
|
try:
|
|
@@ -308,6 +312,9 @@ class ReplBase:
|
|
|
308
312
|
if user_input.lower() in ["help", "h"]:
|
|
309
313
|
self.show_help()
|
|
310
314
|
elif user_input.lower() in self.exit_keywords:
|
|
315
|
+
self.print(
|
|
316
|
+
f"[bold yellow]Exiting REPL ({self.title})...[/bold yellow]"
|
|
317
|
+
)
|
|
311
318
|
break
|
|
312
319
|
else:
|
|
313
320
|
args = shlex.split(user_input)
|
|
@@ -339,7 +346,6 @@ class ReplBase:
|
|
|
339
346
|
|
|
340
347
|
cmd.command(cmd.parser.parse_args(cmd_args))
|
|
341
348
|
else:
|
|
342
|
-
cmd_args = cmd_args or cmd.def_args
|
|
343
349
|
if cmd.def_kwargs:
|
|
344
350
|
cmd.command(*cmd_args, **cmd.def_kwargs)
|
|
345
351
|
else:
|
|
@@ -349,7 +355,9 @@ class ReplBase:
|
|
|
349
355
|
"[bold yellow][WARNING]: No function provided for command[/bold yellow]"
|
|
350
356
|
)
|
|
351
357
|
except (EOFError, KeyboardInterrupt):
|
|
352
|
-
self.print(
|
|
358
|
+
self.print(
|
|
359
|
+
f"[bold yellow]Exiting REPL ({self.title})...[/bold yellow]"
|
|
360
|
+
)
|
|
353
361
|
break
|
|
354
362
|
|
|
355
363
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|