k3shell 0.1.0__tar.gz → 0.1.1__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.
- k3shell-0.1.1/LICENSE +21 -0
- k3shell-0.1.1/PKG-INFO +157 -0
- k3shell-0.1.0/k3shell/synopsis.py → k3shell-0.1.1/README.md +121 -74
- {k3shell-0.1.0/k3shell → k3shell-0.1.1}/__init__.py +4 -2
- {k3shell-0.1.0/k3shell → k3shell-0.1.1}/command.py +12 -18
- k3shell-0.1.1/k3shell.egg-info/PKG-INFO +157 -0
- k3shell-0.1.1/k3shell.egg-info/SOURCES.txt +16 -0
- k3shell-0.1.1/k3shell.egg-info/requires.txt +16 -0
- k3shell-0.1.1/pyproject.toml +59 -0
- k3shell-0.1.1/synopsis.py +78 -0
- k3shell-0.1.1/test/test_doctest.py +8 -0
- k3shell-0.1.1/test/test_k3shell.py +259 -0
- k3shell-0.1.0/PKG-INFO +0 -137
- k3shell-0.1.0/k3shell/setup.py +0 -23
- k3shell-0.1.0/k3shell.egg-info/PKG-INFO +0 -137
- k3shell-0.1.0/k3shell.egg-info/SOURCES.txt +0 -10
- k3shell-0.1.0/k3shell.egg-info/requires.txt +0 -1
- k3shell-0.1.0/setup.py +0 -23
- {k3shell-0.1.0 → k3shell-0.1.1}/k3shell.egg-info/dependency_links.txt +0 -0
- {k3shell-0.1.0 → k3shell-0.1.1}/k3shell.egg-info/top_level.txt +0 -0
- {k3shell-0.1.0 → k3shell-0.1.1}/setup.cfg +0 -0
k3shell-0.1.1/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 张炎泼
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
k3shell-0.1.1/PKG-INFO
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: k3shell
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Shell command dispatcher with nested subcommand support
|
|
5
|
+
Author-email: Zhang Yanpo <drdr.xp@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/pykit3/k3shell
|
|
8
|
+
Project-URL: Documentation, https://k3shell.readthedocs.io
|
|
9
|
+
Keywords: shell,command,cli,subcommand,argparse
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Requires-Python: >=3.9
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: k3dict
|
|
23
|
+
Provides-Extra: dev
|
|
24
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
25
|
+
Requires-Dist: ruff; extra == "dev"
|
|
26
|
+
Requires-Dist: coverage; extra == "dev"
|
|
27
|
+
Provides-Extra: publish
|
|
28
|
+
Requires-Dist: build; extra == "publish"
|
|
29
|
+
Requires-Dist: twine; extra == "publish"
|
|
30
|
+
Requires-Dist: pk3; extra == "publish"
|
|
31
|
+
Provides-Extra: docs
|
|
32
|
+
Requires-Dist: mkdocs>=1.5; extra == "docs"
|
|
33
|
+
Requires-Dist: mkdocs-material>=9.0; extra == "docs"
|
|
34
|
+
Requires-Dist: mkdocstrings[python]>=0.24; extra == "docs"
|
|
35
|
+
Dynamic: license-file
|
|
36
|
+
|
|
37
|
+
# k3shell
|
|
38
|
+
|
|
39
|
+
[](https://github.com/pykit3/k3shell/actions/workflows/python-package.yml)
|
|
40
|
+
[](https://travis-ci.com/pykit3/k3shell)
|
|
41
|
+
[](https://k3shell.readthedocs.io/en/stable/?badge=stable)
|
|
42
|
+
[](https://pypi.org/project/k3shell)
|
|
43
|
+
|
|
44
|
+
A python module to manage commands.
|
|
45
|
+
|
|
46
|
+
k3shell is a component of [pykit3] project: a python3 toolkit set.
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
# Name
|
|
50
|
+
|
|
51
|
+
k3shell
|
|
52
|
+
|
|
53
|
+
# Status
|
|
54
|
+
|
|
55
|
+
The library is considered production ready.
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
# Install
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
pip install k3shell
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
# Synopsis
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
|
|
70
|
+
import k3shell
|
|
71
|
+
import sys
|
|
72
|
+
arguments = {
|
|
73
|
+
'echo_repr': (
|
|
74
|
+
lambda x: sys.stdout.write(repr(x)),
|
|
75
|
+
('x', {'nargs': '+', 'help': 'just an input message'}),
|
|
76
|
+
),
|
|
77
|
+
|
|
78
|
+
'foo': {
|
|
79
|
+
'bar': lambda: sys.stdout.write('bar'),
|
|
80
|
+
|
|
81
|
+
'bob': {
|
|
82
|
+
'plus': (
|
|
83
|
+
lambda x, y: sys.stdout.write(str(x + y)),
|
|
84
|
+
('x', {'type': int, help: 'an int is needed'}),
|
|
85
|
+
('y', {'type': int, help: 'an int is needed'}),
|
|
86
|
+
),
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
'__add_help__': {
|
|
91
|
+
('echo_repr',) : 'output what is input.',
|
|
92
|
+
('foo', 'bar',) : 'print a "bar".',
|
|
93
|
+
('foo', 'bob', 'plus',) : 'do addition operation with 2 numbers.',
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
'__description__': 'this is an example command.',
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
k3shell.command(**arguments)
|
|
100
|
+
"""
|
|
101
|
+
|
|
102
|
+
then you can execute your command as:
|
|
103
|
+
|
|
104
|
+
python demo.py echo_repr hello!
|
|
105
|
+
# 'hello!'
|
|
106
|
+
|
|
107
|
+
python demo.py foo bar
|
|
108
|
+
# 'bar'
|
|
109
|
+
|
|
110
|
+
python demo.py foo bob plus 1 2
|
|
111
|
+
# 3
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
and you can get a usage help message like:
|
|
115
|
+
|
|
116
|
+
$ python demo.py -h
|
|
117
|
+
---------------------------
|
|
118
|
+
usage: demo.py [-h] {echo_repr, foo bar, foo bob plus} ...
|
|
119
|
+
|
|
120
|
+
this is an example command.
|
|
121
|
+
|
|
122
|
+
positional arguments:
|
|
123
|
+
{echo_repr, foo bar, foo bob plus} commands to select ...
|
|
124
|
+
echo_repr output what is input.
|
|
125
|
+
foo bar print a "bar".
|
|
126
|
+
foo bob plus do addition operation with 2 numbers.
|
|
127
|
+
|
|
128
|
+
optional arguments:
|
|
129
|
+
-h, --help show this help message and exit
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
$ python demo.py foo bob plus -h
|
|
133
|
+
--------------------------
|
|
134
|
+
usage: demo.py foo bob plus [-h] x y
|
|
135
|
+
|
|
136
|
+
positional arguments:
|
|
137
|
+
x an int is need
|
|
138
|
+
y an int is need
|
|
139
|
+
|
|
140
|
+
optional arguments:
|
|
141
|
+
-h, --help show this help message and exit
|
|
142
|
+
|
|
143
|
+
"""
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
# Author
|
|
147
|
+
|
|
148
|
+
Wenbo Li(李文博) <wenbo.li@baishancloud.com>
|
|
149
|
+
|
|
150
|
+
# Copyright and License
|
|
151
|
+
|
|
152
|
+
The MIT License (MIT)
|
|
153
|
+
|
|
154
|
+
Copyright (c) 2017 Wenbo Li(李文博) <wenbo.li@baishancloud.com>
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
[pykit3]: https://github.com/pykit3
|
|
@@ -1,74 +1,121 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
1
|
+
# k3shell
|
|
2
|
+
|
|
3
|
+
[](https://github.com/pykit3/k3shell/actions/workflows/python-package.yml)
|
|
4
|
+
[](https://travis-ci.com/pykit3/k3shell)
|
|
5
|
+
[](https://k3shell.readthedocs.io/en/stable/?badge=stable)
|
|
6
|
+
[](https://pypi.org/project/k3shell)
|
|
7
|
+
|
|
8
|
+
A python module to manage commands.
|
|
9
|
+
|
|
10
|
+
k3shell is a component of [pykit3] project: a python3 toolkit set.
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
# Name
|
|
14
|
+
|
|
15
|
+
k3shell
|
|
16
|
+
|
|
17
|
+
# Status
|
|
18
|
+
|
|
19
|
+
The library is considered production ready.
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
# Install
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
pip install k3shell
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
# Synopsis
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
|
|
34
|
+
import k3shell
|
|
35
|
+
import sys
|
|
36
|
+
arguments = {
|
|
37
|
+
'echo_repr': (
|
|
38
|
+
lambda x: sys.stdout.write(repr(x)),
|
|
39
|
+
('x', {'nargs': '+', 'help': 'just an input message'}),
|
|
40
|
+
),
|
|
41
|
+
|
|
42
|
+
'foo': {
|
|
43
|
+
'bar': lambda: sys.stdout.write('bar'),
|
|
44
|
+
|
|
45
|
+
'bob': {
|
|
46
|
+
'plus': (
|
|
47
|
+
lambda x, y: sys.stdout.write(str(x + y)),
|
|
48
|
+
('x', {'type': int, help: 'an int is needed'}),
|
|
49
|
+
('y', {'type': int, help: 'an int is needed'}),
|
|
50
|
+
),
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
'__add_help__': {
|
|
55
|
+
('echo_repr',) : 'output what is input.',
|
|
56
|
+
('foo', 'bar',) : 'print a "bar".',
|
|
57
|
+
('foo', 'bob', 'plus',) : 'do addition operation with 2 numbers.',
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
'__description__': 'this is an example command.',
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
k3shell.command(**arguments)
|
|
64
|
+
"""
|
|
65
|
+
|
|
66
|
+
then you can execute your command as:
|
|
67
|
+
|
|
68
|
+
python demo.py echo_repr hello!
|
|
69
|
+
# 'hello!'
|
|
70
|
+
|
|
71
|
+
python demo.py foo bar
|
|
72
|
+
# 'bar'
|
|
73
|
+
|
|
74
|
+
python demo.py foo bob plus 1 2
|
|
75
|
+
# 3
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
and you can get a usage help message like:
|
|
79
|
+
|
|
80
|
+
$ python demo.py -h
|
|
81
|
+
---------------------------
|
|
82
|
+
usage: demo.py [-h] {echo_repr, foo bar, foo bob plus} ...
|
|
83
|
+
|
|
84
|
+
this is an example command.
|
|
85
|
+
|
|
86
|
+
positional arguments:
|
|
87
|
+
{echo_repr, foo bar, foo bob plus} commands to select ...
|
|
88
|
+
echo_repr output what is input.
|
|
89
|
+
foo bar print a "bar".
|
|
90
|
+
foo bob plus do addition operation with 2 numbers.
|
|
91
|
+
|
|
92
|
+
optional arguments:
|
|
93
|
+
-h, --help show this help message and exit
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
$ python demo.py foo bob plus -h
|
|
97
|
+
--------------------------
|
|
98
|
+
usage: demo.py foo bob plus [-h] x y
|
|
99
|
+
|
|
100
|
+
positional arguments:
|
|
101
|
+
x an int is need
|
|
102
|
+
y an int is need
|
|
103
|
+
|
|
104
|
+
optional arguments:
|
|
105
|
+
-h, --help show this help message and exit
|
|
106
|
+
|
|
107
|
+
"""
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
# Author
|
|
111
|
+
|
|
112
|
+
Wenbo Li(李文博) <wenbo.li@baishancloud.com>
|
|
113
|
+
|
|
114
|
+
# Copyright and License
|
|
115
|
+
|
|
116
|
+
The MIT License (MIT)
|
|
117
|
+
|
|
118
|
+
Copyright (c) 2017 Wenbo Li(李文博) <wenbo.li@baishancloud.com>
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
[pykit3]: https://github.com/pykit3
|
|
@@ -45,16 +45,14 @@ def command(**kwargs):
|
|
|
45
45
|
try:
|
|
46
46
|
cmds = []
|
|
47
47
|
while len(inputs) > 0 and inputs[0] in root:
|
|
48
|
-
|
|
49
48
|
k = inputs.pop(0)
|
|
50
49
|
cmds.append(k)
|
|
51
50
|
node = root[k]
|
|
52
51
|
|
|
53
52
|
if is_node_executable(node):
|
|
54
|
-
|
|
55
53
|
call_able, args = parse_executable_node(parser, cmds, node, inputs)
|
|
56
54
|
try:
|
|
57
|
-
logger.debug("command: " + repr(cmds) +
|
|
55
|
+
logger.debug("command: " + repr(cmds) + " args: " + repr(args) + " cwd: " + repr(os.getcwd()))
|
|
58
56
|
rc = call_able(*args)
|
|
59
57
|
logger.debug(repr(rc))
|
|
60
58
|
if rc is True or rc == 0 or rc is None:
|
|
@@ -71,15 +69,14 @@ def command(**kwargs):
|
|
|
71
69
|
root = node
|
|
72
70
|
|
|
73
71
|
if need_to_show_help(parser):
|
|
74
|
-
|
|
75
72
|
if len(cmds) > 0:
|
|
76
|
-
argv = [
|
|
73
|
+
argv = [" ".join(cmds)] + inputs
|
|
77
74
|
else:
|
|
78
75
|
argv = inputs
|
|
79
76
|
|
|
80
77
|
parser.parse_args(argv)
|
|
81
78
|
else:
|
|
82
|
-
sys.stderr.write(
|
|
79
|
+
sys.stderr.write("No such command: " + " ".join(sys.argv[1:]))
|
|
83
80
|
|
|
84
81
|
sys.exit(2)
|
|
85
82
|
|
|
@@ -92,24 +89,23 @@ def command(**kwargs):
|
|
|
92
89
|
def add_command_help(commands):
|
|
93
90
|
new_cmds = copy.deepcopy(commands)
|
|
94
91
|
|
|
95
|
-
help_msgs = new_cmds.get(
|
|
96
|
-
desc = new_cmds.get(
|
|
92
|
+
help_msgs = new_cmds.get("__add_help__")
|
|
93
|
+
desc = new_cmds.get("__description__")
|
|
97
94
|
|
|
98
|
-
for k in (
|
|
95
|
+
for k in ("__add_help__", "__description__"):
|
|
99
96
|
if k in new_cmds:
|
|
100
97
|
del new_cmds[k]
|
|
101
98
|
|
|
102
99
|
if help_msgs is None:
|
|
103
100
|
return new_cmds, None
|
|
104
101
|
|
|
105
|
-
parser = argparse.ArgumentParser(description=desc, epilog=
|
|
102
|
+
parser = argparse.ArgumentParser(description=desc, epilog="\n")
|
|
106
103
|
|
|
107
|
-
subparsers = parser.add_subparsers(help=
|
|
104
|
+
subparsers = parser.add_subparsers(help=" command(s) to select ...")
|
|
108
105
|
|
|
109
106
|
for cmds, execute_able in k3dict.depth_iter(new_cmds):
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
cmd = ' '.join(cmds)
|
|
107
|
+
help = help_msgs.get(tuple(cmds), "")
|
|
108
|
+
cmd = " ".join(cmds)
|
|
113
109
|
|
|
114
110
|
cmd_parser = subparsers.add_parser(cmd, help=help)
|
|
115
111
|
|
|
@@ -129,7 +125,7 @@ def add_param_help(parser, param_msgs):
|
|
|
129
125
|
params = []
|
|
130
126
|
for param, msg in param_msgs:
|
|
131
127
|
parser.add_argument(param, **msg)
|
|
132
|
-
param = param.lstrip(
|
|
128
|
+
param = param.lstrip("-")
|
|
133
129
|
params.append(param)
|
|
134
130
|
|
|
135
131
|
return params
|
|
@@ -137,14 +133,13 @@ def add_param_help(parser, param_msgs):
|
|
|
137
133
|
|
|
138
134
|
def parse_executable_node(parser, cmds, execute_able, args):
|
|
139
135
|
if not need_to_show_help(parser):
|
|
140
|
-
|
|
141
136
|
# no __add_help__ but has paramter help message
|
|
142
137
|
if args_need_to_parse(execute_able):
|
|
143
138
|
return execute_able[0], args
|
|
144
139
|
|
|
145
140
|
return execute_able, args
|
|
146
141
|
|
|
147
|
-
args_parsed = parser.parse_args([
|
|
142
|
+
args_parsed = parser.parse_args([" ".join(cmds)] + args)
|
|
148
143
|
# to dict
|
|
149
144
|
args_parsed = vars(args_parsed)
|
|
150
145
|
|
|
@@ -155,7 +150,6 @@ def parse_executable_node(parser, cmds, execute_able, args):
|
|
|
155
150
|
|
|
156
151
|
args = [args_parsed.get(x) for x in params]
|
|
157
152
|
|
|
158
|
-
|
|
159
153
|
return call_able, args
|
|
160
154
|
|
|
161
155
|
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: k3shell
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Shell command dispatcher with nested subcommand support
|
|
5
|
+
Author-email: Zhang Yanpo <drdr.xp@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/pykit3/k3shell
|
|
8
|
+
Project-URL: Documentation, https://k3shell.readthedocs.io
|
|
9
|
+
Keywords: shell,command,cli,subcommand,argparse
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Requires-Python: >=3.9
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: k3dict
|
|
23
|
+
Provides-Extra: dev
|
|
24
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
25
|
+
Requires-Dist: ruff; extra == "dev"
|
|
26
|
+
Requires-Dist: coverage; extra == "dev"
|
|
27
|
+
Provides-Extra: publish
|
|
28
|
+
Requires-Dist: build; extra == "publish"
|
|
29
|
+
Requires-Dist: twine; extra == "publish"
|
|
30
|
+
Requires-Dist: pk3; extra == "publish"
|
|
31
|
+
Provides-Extra: docs
|
|
32
|
+
Requires-Dist: mkdocs>=1.5; extra == "docs"
|
|
33
|
+
Requires-Dist: mkdocs-material>=9.0; extra == "docs"
|
|
34
|
+
Requires-Dist: mkdocstrings[python]>=0.24; extra == "docs"
|
|
35
|
+
Dynamic: license-file
|
|
36
|
+
|
|
37
|
+
# k3shell
|
|
38
|
+
|
|
39
|
+
[](https://github.com/pykit3/k3shell/actions/workflows/python-package.yml)
|
|
40
|
+
[](https://travis-ci.com/pykit3/k3shell)
|
|
41
|
+
[](https://k3shell.readthedocs.io/en/stable/?badge=stable)
|
|
42
|
+
[](https://pypi.org/project/k3shell)
|
|
43
|
+
|
|
44
|
+
A python module to manage commands.
|
|
45
|
+
|
|
46
|
+
k3shell is a component of [pykit3] project: a python3 toolkit set.
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
# Name
|
|
50
|
+
|
|
51
|
+
k3shell
|
|
52
|
+
|
|
53
|
+
# Status
|
|
54
|
+
|
|
55
|
+
The library is considered production ready.
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
# Install
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
pip install k3shell
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
# Synopsis
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
|
|
70
|
+
import k3shell
|
|
71
|
+
import sys
|
|
72
|
+
arguments = {
|
|
73
|
+
'echo_repr': (
|
|
74
|
+
lambda x: sys.stdout.write(repr(x)),
|
|
75
|
+
('x', {'nargs': '+', 'help': 'just an input message'}),
|
|
76
|
+
),
|
|
77
|
+
|
|
78
|
+
'foo': {
|
|
79
|
+
'bar': lambda: sys.stdout.write('bar'),
|
|
80
|
+
|
|
81
|
+
'bob': {
|
|
82
|
+
'plus': (
|
|
83
|
+
lambda x, y: sys.stdout.write(str(x + y)),
|
|
84
|
+
('x', {'type': int, help: 'an int is needed'}),
|
|
85
|
+
('y', {'type': int, help: 'an int is needed'}),
|
|
86
|
+
),
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
'__add_help__': {
|
|
91
|
+
('echo_repr',) : 'output what is input.',
|
|
92
|
+
('foo', 'bar',) : 'print a "bar".',
|
|
93
|
+
('foo', 'bob', 'plus',) : 'do addition operation with 2 numbers.',
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
'__description__': 'this is an example command.',
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
k3shell.command(**arguments)
|
|
100
|
+
"""
|
|
101
|
+
|
|
102
|
+
then you can execute your command as:
|
|
103
|
+
|
|
104
|
+
python demo.py echo_repr hello!
|
|
105
|
+
# 'hello!'
|
|
106
|
+
|
|
107
|
+
python demo.py foo bar
|
|
108
|
+
# 'bar'
|
|
109
|
+
|
|
110
|
+
python demo.py foo bob plus 1 2
|
|
111
|
+
# 3
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
and you can get a usage help message like:
|
|
115
|
+
|
|
116
|
+
$ python demo.py -h
|
|
117
|
+
---------------------------
|
|
118
|
+
usage: demo.py [-h] {echo_repr, foo bar, foo bob plus} ...
|
|
119
|
+
|
|
120
|
+
this is an example command.
|
|
121
|
+
|
|
122
|
+
positional arguments:
|
|
123
|
+
{echo_repr, foo bar, foo bob plus} commands to select ...
|
|
124
|
+
echo_repr output what is input.
|
|
125
|
+
foo bar print a "bar".
|
|
126
|
+
foo bob plus do addition operation with 2 numbers.
|
|
127
|
+
|
|
128
|
+
optional arguments:
|
|
129
|
+
-h, --help show this help message and exit
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
$ python demo.py foo bob plus -h
|
|
133
|
+
--------------------------
|
|
134
|
+
usage: demo.py foo bob plus [-h] x y
|
|
135
|
+
|
|
136
|
+
positional arguments:
|
|
137
|
+
x an int is need
|
|
138
|
+
y an int is need
|
|
139
|
+
|
|
140
|
+
optional arguments:
|
|
141
|
+
-h, --help show this help message and exit
|
|
142
|
+
|
|
143
|
+
"""
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
# Author
|
|
147
|
+
|
|
148
|
+
Wenbo Li(李文博) <wenbo.li@baishancloud.com>
|
|
149
|
+
|
|
150
|
+
# Copyright and License
|
|
151
|
+
|
|
152
|
+
The MIT License (MIT)
|
|
153
|
+
|
|
154
|
+
Copyright (c) 2017 Wenbo Li(李文博) <wenbo.li@baishancloud.com>
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
[pykit3]: https://github.com/pykit3
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
__init__.py
|
|
4
|
+
command.py
|
|
5
|
+
pyproject.toml
|
|
6
|
+
synopsis.py
|
|
7
|
+
./__init__.py
|
|
8
|
+
./command.py
|
|
9
|
+
./synopsis.py
|
|
10
|
+
k3shell.egg-info/PKG-INFO
|
|
11
|
+
k3shell.egg-info/SOURCES.txt
|
|
12
|
+
k3shell.egg-info/dependency_links.txt
|
|
13
|
+
k3shell.egg-info/requires.txt
|
|
14
|
+
k3shell.egg-info/top_level.txt
|
|
15
|
+
test/test_doctest.py
|
|
16
|
+
test/test_k3shell.py
|