c2e 1.dev10__tar.gz → 1.dev11__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.4
2
2
  Name: c2e
3
- Version: 1.dev10
3
+ Version: 1.dev11
4
4
  Summary: C2E: Console Command Engine
5
5
  Author: iFamished
6
6
  License: GPL-3.0
@@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
7
7
 
8
8
  [project]
9
9
  name = "c2e"
10
- version = "1-dev.10"
10
+ version = "1-dev.11"
11
11
  description = "C2E: Console Command Engine"
12
12
  readme = "README.md"
13
13
  requires-python = ">=3.14"
@@ -0,0 +1,127 @@
1
+ from mapres import res
2
+ from .dsl import COMMANDS, parse_line, help_command, help_child, help_arg
3
+
4
+
5
+ def dispatch(cli, line):
6
+ p = parse_line(line)
7
+ if not p.sub:
8
+ return
9
+
10
+ cmd = COMMANDS.get(p.sub)
11
+ if not cmd:
12
+ return cli.safePrint(res(f'<red>Error:<reset> <gray>Unknown command {p.sub}<reset>'))
13
+
14
+ if 'help' in p.flags and not p.pos:
15
+ return cli.safePrint(help_command(cmd))
16
+
17
+ if cmd.children:
18
+ if not p.pos:
19
+ return cli.safePrint(res('<red>Error:<reset> <gray>Missing subcommand<reset>'))
20
+
21
+ cname = p.pos[0]
22
+ child = cmd.children.get(cname)
23
+ if not child:
24
+ return cli.safePrint(res(f'<red>Error:<reset> <gray>Unknown subcommand {cname}<reset>'))
25
+
26
+ # child help
27
+ if 'help' in p.flags and len(p.pos) == 1:
28
+ return cli.safePrint(help_child(child))
29
+
30
+ if 'help' in p.flags and len(p.pos) >= 2:
31
+ an = p.pos[1]
32
+ meta = child.args_meta.get(an)
33
+ if not meta:
34
+ return cli.safePrint(res(f'<red>Error:<reset> <gray>Unknown argument {an}<reset>'))
35
+ return cli.safePrint(help_arg(child, meta))
36
+
37
+ arg = p.pos[1] if len(p.pos) > 1 else None
38
+ if child.requires_arg and arg is None:
39
+ return cli.safePrint(
40
+ res(f'<red>Error:<reset> <gray>Subcommand {child.name} requires an argument<reset>')
41
+ )
42
+
43
+ # bind params/flags into child.func globals
44
+ g = child.func.__globals__
45
+
46
+ for n, ps in child.params.items():
47
+ if n in p.params:
48
+ try:
49
+ v = ps.type_(p.params[n])
50
+ except Exception:
51
+ v = ps.default
52
+ else:
53
+ v = ps.default
54
+
55
+ def wrap(f=ps.func, val=v):
56
+ def w():
57
+ return f(val)
58
+ return w
59
+
60
+ g[n] = wrap()
61
+
62
+ for n, fs in child.flags.items():
63
+ present = n in p.flags
64
+
65
+ def wrap(f=fs.func, pr=present):
66
+ def w():
67
+ return pr
68
+ return w
69
+
70
+ g[n] = wrap()
71
+
72
+ f = child.func
73
+ if f.__code__.co_argcount >= 2:
74
+ return f(cli, arg)
75
+ return f(cli)
76
+
77
+ # This is the path your `stats` command should use.
78
+ # p.pos[0] is the "arg" (e.g. ram/cpu/uptime/...)
79
+ arg = p.pos[0] if p.pos else None
80
+
81
+ # arg-level help for top-level commands
82
+ if 'help' in p.flags and arg is not None:
83
+ meta = cmd.args_meta.get(arg)
84
+ if not meta:
85
+ return cli.safePrint(res(f'<red>Error:<reset> <gray>Unknown argument {arg}<reset>'))
86
+ # reuse help_arg, pretending cmd is a "child" of a synthetic parent
87
+ # or write a dedicated help if you want; for now we just show command help
88
+ return cli.safePrint(help_command(cmd))
89
+
90
+ if cmd.requires_arg and arg is None:
91
+ return cli.safePrint(
92
+ res(f'<red>Error:<reset> <gray>Command {cmd.name} requires an argument<reset>')
93
+ )
94
+
95
+ # bind params/flags into cmd.func globals
96
+ g = cmd.func.__globals__
97
+
98
+ for n, ps in cmd.params.items():
99
+ if n in p.params:
100
+ try:
101
+ v = ps.type_(p.params[n])
102
+ except Exception:
103
+ v = ps.default
104
+ else:
105
+ v = ps.default
106
+
107
+ def wrap(f=ps.func, val=v):
108
+ def w():
109
+ return f(val)
110
+ return w
111
+
112
+ g[n] = wrap()
113
+
114
+ for n, fs in cmd.flags.items():
115
+ present = n in p.flags
116
+
117
+ def wrap(f=fs.func, pr=present):
118
+ def w():
119
+ return pr
120
+ return w
121
+
122
+ g[n] = wrap()
123
+
124
+ f = cmd.func
125
+ if f.__code__.co_argcount >= 2:
126
+ return f(cli, arg)
127
+ return f(cli)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: c2e
3
- Version: 1.dev10
3
+ Version: 1.dev11
4
4
  Summary: C2E: Console Command Engine
5
5
  Author: iFamished
6
6
  License: GPL-3.0
@@ -1,72 +0,0 @@
1
- from mapres import res
2
- from .dsl import COMMANDS, parse_line, help_command, help_child, help_arg
3
-
4
-
5
- def dispatch(cli, line):
6
- p = parse_line(line)
7
- if not p.sub:
8
- return
9
-
10
- cmd = COMMANDS.get(p.sub)
11
- if not cmd:
12
- return cli.safePrint(res(f'<red>Error:<reset> <gray>Unknown command {p.sub}<reset>'))
13
-
14
- if 'help' in p.flags and not p.pos:
15
- return cli.safePrint(help_command(cmd))
16
-
17
- if cmd.children:
18
- if not p.pos:
19
- return cli.safePrint(res('<red>Error:<reset> <gray>Missing subcommand<reset>'))
20
- else:
21
- return cmd.func(cli)
22
-
23
- cname = p.pos[0]
24
- child = cmd.children.get(cname)
25
- if not child:
26
- return cli.safePrint(res(f'<red>Error:<reset> <gray>Unknown subcommand {cname}<reset>'))
27
-
28
- if 'help' in p.flags and len(p.pos) == 1:
29
- return cli.safePrint(help_child(child))
30
-
31
- if 'help' in p.flags and len(p.pos) >= 2:
32
- an = p.pos[1]
33
- meta = child.args_meta.get(an)
34
- if not meta:
35
- return cli.safePrint(res(f'<red>Error:<reset> <gray>Unknown argument {an}<reset>'))
36
- return cli.safePrint(help_arg(child, meta))
37
-
38
- arg = p.pos[1] if len(p.pos) > 1 else None
39
- if child.requires_arg and arg is None:
40
- return cli.safePrint(res(f'<red>Error:<reset> <gray>Subcommand {child.name} requires an argument<reset>'))
41
-
42
- g = child.func.__globals__
43
- for n, ps in child.params.items():
44
- if n in p.params:
45
- try:
46
- v = ps.type_(p.params[n])
47
- except:
48
- v = ps.default
49
- else:
50
- v = ps.default
51
-
52
- def wrap(f=ps.func, val=v):
53
- def w():
54
- return f(val)
55
- return w
56
-
57
- g[n] = wrap()
58
-
59
- for n, fs in child.flags.items():
60
- present = n in p.flags
61
-
62
- def wrap(f=fs.func, pr=present):
63
- def w():
64
- return pr
65
- return w
66
-
67
- g[n] = wrap()
68
-
69
- f = child.func
70
- if f.__code__.co_argcount >= 2:
71
- return f(cli, arg)
72
- return f(cli)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes