hmmmmm
This commit is contained in:
parent
55e167d0c1
commit
4e9a908a97
@ -7,7 +7,8 @@ class CallBackDescriptor:
|
||||
instance.__dict__[self.callback_name] = value
|
||||
|
||||
def __get__(self, instance, owner):
|
||||
if instance is None:
|
||||
return self
|
||||
else:
|
||||
return instance.__dict__[self.callback_name]
|
||||
return (
|
||||
self
|
||||
if instance is None
|
||||
else instance.__dict__.get(self.callback_name)
|
||||
)
|
@ -5,6 +5,7 @@
|
||||
# -------------------------------
|
||||
|
||||
import re
|
||||
from dataclasses import dataclass
|
||||
from typing import Callable, List, Optional, Union
|
||||
|
||||
from .descriptor import CallBackDescriptor
|
||||
@ -56,7 +57,7 @@ def check_name(name: Union[str, List[str]]) -> None:
|
||||
"""
|
||||
if isinstance(name, str) and EMPTY_WORDS.search(name):
|
||||
raise IllegalArgumentName("The name of argument must not contains empty words.")
|
||||
elif isinstance(name, list) and all([(not isinstance(i, str)) and EMPTY_WORDS.search(i) for i in name]):
|
||||
elif isinstance(name, list) and all((not isinstance(i, str)) and EMPTY_WORDS.search(i) for i in name):
|
||||
raise IllegalArgumentName("The name of shortcut must be 'str', and must not contains empty words.")
|
||||
else:
|
||||
raise TypeError("The type of name must be 'str' or 'list[str]'.")
|
||||
@ -66,14 +67,18 @@ class Parsed:
|
||||
...
|
||||
|
||||
|
||||
@dataclass
|
||||
class Argument:
|
||||
def __init__(self, name, shortcut, optional):
|
||||
...
|
||||
name: str
|
||||
shortcuts: List[str]
|
||||
optional: bool
|
||||
type: type
|
||||
|
||||
|
||||
@dataclass
|
||||
class Flag:
|
||||
def __init__(self, name, shortcut):
|
||||
...
|
||||
name: str
|
||||
shortcuts: List[str]
|
||||
|
||||
|
||||
class Literal:
|
||||
@ -84,14 +89,22 @@ class Literal:
|
||||
def __init__(self, name: str):
|
||||
self.name: str = name
|
||||
self.sub: List[Self] = []
|
||||
self._tip: Optional[str] = None
|
||||
|
||||
self._doc: Optional[str] = None
|
||||
self._tip: Optional[CallBack] = None
|
||||
self._func: Optional[CallBack] = None
|
||||
self._err_callback: Optional[CallBack] = None
|
||||
self._args: List[Argument] = []
|
||||
self._flags: List[Argument]
|
||||
|
||||
def __call__(self, *nodes) -> Self:
|
||||
self.sub += nodes
|
||||
return self
|
||||
|
||||
def __repr__(self):
|
||||
attrs = (k for k in self.__dict__ if not (k.startswith("__") and k.endswith("__")))
|
||||
return f"{self.__class__.__name__}({', '.join(f'{k}={v!r}' for k in attrs if (v := self.__dict__[k]))})"
|
||||
|
||||
def arg(
|
||||
self,
|
||||
name: str,
|
||||
@ -102,39 +115,43 @@ class Literal:
|
||||
check_name(name)
|
||||
if shortcuts is not None and len(shortcuts) != 0:
|
||||
check_name(shortcuts)
|
||||
Argument(...)
|
||||
...
|
||||
Argument(name=name, shortcuts=shortcuts, optional=optional, type=type)
|
||||
return self
|
||||
|
||||
def arg_group(self, args: List[Argument], exclusive: bool = False):
|
||||
...
|
||||
|
||||
def flag(self, name: str, shortcuts: Optional[List[str]] = None) -> Self:
|
||||
check_name(name)
|
||||
if shortcuts is not None and len(shortcuts) != 0:
|
||||
check_name(shortcuts)
|
||||
Flag(...)
|
||||
# Flag(...)
|
||||
...
|
||||
return self
|
||||
|
||||
def flag_group(self, flags: List[Flag], exclusive: bool = False):
|
||||
...
|
||||
|
||||
def error(self, callback: CallBack) -> Self:
|
||||
check_once(self, "_err_callback")
|
||||
self._err_callback = callback
|
||||
return self
|
||||
|
||||
def run(self, func: CallBack) -> Self:
|
||||
check_once(self, "_func")
|
||||
self._func = func
|
||||
return self
|
||||
|
||||
def tip(self, tip: CallBack) -> Self:
|
||||
check_once(self, "_tip")
|
||||
self._tip = tip
|
||||
return self
|
||||
|
||||
def parse(self) -> Parsed:
|
||||
def parse(self, cmd: Union[str, List[str]]) -> Parsed:
|
||||
...
|
||||
|
||||
def to_doc(self) -> str:
|
||||
...
|
||||
self._doc = ...
|
||||
return self._doc
|
||||
|
||||
|
||||
def builder(node: Literal) -> Literal:
|
||||
...
|
||||
...
|
||||
|
@ -11,7 +11,6 @@ from typing import List, Tuple, Optional
|
||||
|
||||
from lib_not_dr.types import Options, Version, VersionRequirement
|
||||
|
||||
|
||||
def _add_cmd(cmd: List[str], string: Optional[str]) -> List[str]:
|
||||
if string is not None and string:
|
||||
cmd.append(string)
|
||||
|
Loading…
Reference in New Issue
Block a user