got distracted and made a repl framework.......
This commit is contained in:
parent
0a2d9a5694
commit
c18aa29c58
5 changed files with 227 additions and 17 deletions
|
|
@ -1,7 +1,10 @@
|
|||
from itertools import chain, tee
|
||||
|
||||
from bcrypter.lib.result import Result
|
||||
from bcrypter.cli.opt import Overlap
|
||||
|
||||
class Command:
|
||||
NAME = '[Abstract]Command'
|
||||
NAME = '' # intentionally left empty (invalid name)
|
||||
ARGS = []
|
||||
FLAGS = []
|
||||
OPTIONS = []
|
||||
|
|
@ -21,9 +24,22 @@ class Command:
|
|||
(ie no duplicate names or parsing ambiguity)
|
||||
'''
|
||||
@classmethod
|
||||
def _is_well_defined(cls: Command) -> Result[None]:
|
||||
raise NotImplementedException('Command.is_consistent()')
|
||||
|
||||
def _is_well_defined(cls: Command) -> Result[list[Overlap]]:
|
||||
overlaps: list[Overlap] = []
|
||||
opts = chain(cls.FLAGS, cls.OPTIONS)
|
||||
# Detect duplicate names and duplicate short/longforms
|
||||
for optX in opts:
|
||||
overlap = Overlap.empty(optX)
|
||||
other_opts = tee(opts) # duplicate the opts iterator
|
||||
for optY in other_opts:
|
||||
overlap += Overlap.of(optX, optY)
|
||||
# check if overlap occurred, add to list of all overlaps
|
||||
if not overlap.is_empty():
|
||||
overlaps.append(overlap)
|
||||
if overlaps:
|
||||
return Result.fail(overlaps)
|
||||
return Result.succeed([])
|
||||
|
||||
'''
|
||||
Attempt to match an arg to its flag or option
|
||||
NOTE: _match_arg() assumes _is_well_defined() == True
|
||||
|
|
@ -37,7 +53,10 @@ class Command:
|
|||
|
||||
|
||||
class Builtin(Command):
|
||||
self.NAME = '[Abstract]Builtin'
|
||||
NAME = '' # intentionally left empty (invalid name)
|
||||
ARGS = []
|
||||
FLAGS = []
|
||||
OPTIONS = []
|
||||
def __init__(self,
|
||||
repl_builtins: list[Builtin],
|
||||
repl_cmds: list[Command]) -> None:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue