c2e 1.dev9__py3-none-any.whl → 1.dev11__py3-none-any.whl

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.
c2e/dispatch.py CHANGED
@@ -17,34 +17,89 @@ def dispatch(cli, line):
17
17
  if cmd.children:
18
18
  if not p.pos:
19
19
  return cli.safePrint(res('<red>Error:<reset> <gray>Missing subcommand<reset>'))
20
- else:
21
- return cmd.func(cli)
22
20
 
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>'))
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
27
69
 
28
- if 'help' in p.flags and len(p.pos) == 1:
29
- return cli.safePrint(help_child(child))
70
+ g[n] = wrap()
30
71
 
31
- if 'help' in p.flags and len(p.pos) >= 2:
32
- an = p.pos[1]
33
- meta = child.args_meta.get(an)
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)
34
84
  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))
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
+ )
37
94
 
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>'))
95
+ # bind params/flags into cmd.func globals
96
+ g = cmd.func.__globals__
41
97
 
42
- g = child.func.__globals__
43
- for n, ps in child.params.items():
98
+ for n, ps in cmd.params.items():
44
99
  if n in p.params:
45
100
  try:
46
101
  v = ps.type_(p.params[n])
47
- except:
102
+ except Exception:
48
103
  v = ps.default
49
104
  else:
50
105
  v = ps.default
@@ -56,7 +111,7 @@ def dispatch(cli, line):
56
111
 
57
112
  g[n] = wrap()
58
113
 
59
- for n, fs in child.flags.items():
114
+ for n, fs in cmd.flags.items():
60
115
  present = n in p.flags
61
116
 
62
117
  def wrap(f=fs.func, pr=present):
@@ -66,7 +121,7 @@ def dispatch(cli, line):
66
121
 
67
122
  g[n] = wrap()
68
123
 
69
- f = child.func
124
+ f = cmd.func
70
125
  if f.__code__.co_argcount >= 2:
71
126
  return f(cli, arg)
72
127
  return f(cli)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: c2e
3
- Version: 1.dev9
3
+ Version: 1.dev11
4
4
  Summary: C2E: Console Command Engine
5
5
  Author: iFamished
6
6
  License: GPL-3.0
@@ -0,0 +1,10 @@
1
+ c2e/__init__.py,sha256=RUBqAulgYVahv2kdNx3OxZk2v4khVls31I16L-hO5cU,143
2
+ c2e/colors.py,sha256=rPxMoWSYCxKmhhi1j7v1n7_bmayeeEC7MRmF7f8VoWU,109
3
+ c2e/core.py,sha256=47B4VIofri2AonmB7V7SnPd6Ywvo_lus965wcw-0Vgg,1520
4
+ c2e/dispatch.py,sha256=WX4WWxr2MOY57UDVctv52dFJfQMKl2Tk9NqpZ6Mm9z4,3767
5
+ c2e/dsl.py,sha256=Z5vzMHnIF_2yJFu8jI81i-TFilncmJQOFGLiTLuzF7w,11769
6
+ c2e-1.dev11.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
7
+ c2e-1.dev11.dist-info/METADATA,sha256=ZPn7R6ptBleaB6gjmujk8Tm1Kz-V1Rxg2N3LCBe3vLg,2252
8
+ c2e-1.dev11.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
9
+ c2e-1.dev11.dist-info/top_level.txt,sha256=6sdY2hp5dHTmmPH0RW1YdaTgxo3VM_O9qIq6zatMhsg,4
10
+ c2e-1.dev11.dist-info/RECORD,,
@@ -1,10 +0,0 @@
1
- c2e/__init__.py,sha256=RUBqAulgYVahv2kdNx3OxZk2v4khVls31I16L-hO5cU,143
2
- c2e/colors.py,sha256=rPxMoWSYCxKmhhi1j7v1n7_bmayeeEC7MRmF7f8VoWU,109
3
- c2e/core.py,sha256=47B4VIofri2AonmB7V7SnPd6Ywvo_lus965wcw-0Vgg,1520
4
- c2e/dispatch.py,sha256=p725Hzsy__rhaaDUqO4fJXC-8uGIgyDQ87VoSYToX-g,2022
5
- c2e/dsl.py,sha256=Z5vzMHnIF_2yJFu8jI81i-TFilncmJQOFGLiTLuzF7w,11769
6
- c2e-1.dev9.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
7
- c2e-1.dev9.dist-info/METADATA,sha256=sG__l-g-XTyGgLSTR2umImjUgguvx8R4GCPjFlZ0loQ,2251
8
- c2e-1.dev9.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
9
- c2e-1.dev9.dist-info/top_level.txt,sha256=6sdY2hp5dHTmmPH0RW1YdaTgxo3VM_O9qIq6zatMhsg,4
10
- c2e-1.dev9.dist-info/RECORD,,
File without changes