From ef61a42976e30091c2ef6fca397e496176a40115 Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Tue, 11 Jul 2023 01:56:02 +0800 Subject: [PATCH] some command --- docs/command.md | 88 ++++++++++++++++++++++++++++++++++ lib_not_dr/command/__init__.py | 0 lib_not_dr/nuitka/__init__.py | 0 3 files changed, 88 insertions(+) create mode 100644 docs/command.md create mode 100644 lib_not_dr/command/__init__.py create mode 100644 lib_not_dr/nuitka/__init__.py diff --git a/docs/command.md b/docs/command.md new file mode 100644 index 0000000..8353c44 --- /dev/null +++ b/docs/command.md @@ -0,0 +1,88 @@ +# Command parser + +> By shenjackyuanjie And MSDNicrosoft and Harvey Huskey + +## Usage + +```python +from typing import Callable, Self + +class Literal: + def __init__(self, name: str): + self.name = name + self.sub = [] + self._tip = '' + + def __call__(self, *nodes) -> Self: + self.sub += nodes + return self + + def run(self, func: Callable[[list[str]], None]) -> Self: + return self + + def tip(self, tip: str) -> Self: + return self + + def arg(self, parse_func: Callable[[str], type | None]) -> Self: + return self + + def error(self, callback: Callable[[str], None]) -> Self: + return self + + +builder = Literal('test1')( + Literal('a') + .run(lambda x: print(x)), + Literal('b') + .tip('this is b') + .run(lambda x: print(x))( + Literal('c') + .run(lambda x: print(x)), + Literal('d') + .run(lambda x: print(x)), + ), + ) +``` + +build +- test +- main + - arg:text + - go + - arg:int + - run + + +- command: 主节点 +- literal: 字面量节点 + +## 设计思路 + +```rust +pub enum ArgumentType { + String(String), + Int(i128), + Bool(bool), + Float(f64), +} + +pub type CallBackFunc = Fn(Vec) -> bool; + +pub enum CallBack { + Fn(CallBackFunc), + Message(String), +} + +pub trait Command { + fn new(nodes: Vec) -> Self; + // fn parse(&self, input: String) -> Result; + fn literal(&self, name: String, then: Vec) -> &self; + fn argument(&self, name: String, shortcut: List, optional: Option) -> &self; + fn flag(&self, name: String, shortcut: List, ) -> &self; + fn error(&self, ret: CallBack) -> &self; + fn run(&self, ret: CallBack) -> &self; + fn tip(&self, tip: String) -> &self; + fn to_doc(&self) -> String; + fn exec(&self) -> Option; +} +``` diff --git a/lib_not_dr/command/__init__.py b/lib_not_dr/command/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/lib_not_dr/nuitka/__init__.py b/lib_not_dr/nuitka/__init__.py new file mode 100644 index 0000000..e69de29