fastcommand 0.1.6__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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021-2024 Jason Morley
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.
@@ -0,0 +1,57 @@
1
+ Metadata-Version: 2.1
2
+ Name: fastcommand
3
+ Version: 0.1.6
4
+ Author-email: Jason Morley <hello@jbmorley.co.uk>
5
+ License: MIT License
6
+
7
+ Copyright (c) 2021-2024 Jason Morley
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ of this software and associated documentation files (the "Software"), to deal
11
+ in the Software without restriction, including without limitation the rights
12
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ copies of the Software, and to permit persons to whom the Software is
14
+ furnished to do so, subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in all
17
+ copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ SOFTWARE.
26
+
27
+ Description-Content-Type: text/markdown
28
+ License-File: LICENSE
29
+
30
+ # fastcommand
31
+
32
+ Python module for defining multi-command cli programs
33
+
34
+ ## Description
35
+
36
+ The `fastcommand` module is a lightweight wrapper over `argparse` which aims to make it easier to write multi-command cli programs and utilities. It does so by providing convenience decorators that allow for quickly defining sub-commands.
37
+
38
+ ## Usage
39
+
40
+ ```python
41
+ import fastcommand
42
+
43
+
44
+ @fastcommand.command("hello", help="say hello")
45
+ def command_hello(options):
46
+ print("Hello, World!")
47
+
48
+
49
+ def main():
50
+ cli = fastcommand.CommandParser(description="Simple fastcommand example.")
51
+ cli.use_logging(format="[%(levelname)s] %(message)s")
52
+ cli.run()
53
+
54
+
55
+ if __name__ == "__main__":
56
+ main()
57
+ ```
@@ -0,0 +1,28 @@
1
+ # fastcommand
2
+
3
+ Python module for defining multi-command cli programs
4
+
5
+ ## Description
6
+
7
+ The `fastcommand` module is a lightweight wrapper over `argparse` which aims to make it easier to write multi-command cli programs and utilities. It does so by providing convenience decorators that allow for quickly defining sub-commands.
8
+
9
+ ## Usage
10
+
11
+ ```python
12
+ import fastcommand
13
+
14
+
15
+ @fastcommand.command("hello", help="say hello")
16
+ def command_hello(options):
17
+ print("Hello, World!")
18
+
19
+
20
+ def main():
21
+ cli = fastcommand.CommandParser(description="Simple fastcommand example.")
22
+ cli.use_logging(format="[%(levelname)s] %(message)s")
23
+ cli.run()
24
+
25
+
26
+ if __name__ == "__main__":
27
+ main()
28
+ ```
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env python3
2
+
3
+ # Copyright (c) 2021-2024 Jason Morley
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.
22
+
23
+ from .main import *
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/env python3
2
+
3
+ # Copyright (c) 2021-2024 Jason Morley
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.
22
+
23
+ import argparse
24
+ import functools
25
+ import logging
26
+ import sys
27
+
28
+
29
+ COMMANDS = {}
30
+
31
+
32
+ class Command(object):
33
+
34
+ def __init__(self, name, help, arguments, epilog, formatter_class, callback):
35
+ self.name = name
36
+ self.help = help
37
+ self.arguments = arguments
38
+ self.epilog = epilog
39
+ self.formatter_class = formatter_class
40
+ self.callback = callback
41
+
42
+ class Argument(object):
43
+
44
+ def __init__(self, *args, **kwargs):
45
+ self.args = args
46
+ self.kwargs = kwargs
47
+
48
+
49
+ def command(name, help="", arguments=[], epilog=None, formatter_class=argparse.HelpFormatter):
50
+ def wrapper(fn):
51
+ @functools.wraps(fn)
52
+ def inner(*args, **kwargs):
53
+ return fn(*args, **kwargs)
54
+ COMMANDS[name] = Command(name, help, arguments, epilog, formatter_class, inner)
55
+ return inner
56
+ return wrapper
57
+
58
+
59
+ class CommandParser(object):
60
+
61
+ def __init__(self, *args, **kwargs):
62
+ self.parser = argparse.ArgumentParser(*args, **kwargs)
63
+ subparsers = self.parser.add_subparsers(help="command")
64
+ for name, command in COMMANDS.items():
65
+ subparser = subparsers.add_parser(command.name,
66
+ help=command.help,
67
+ epilog=command.epilog,
68
+ formatter_class=command.formatter_class)
69
+ for argument in command.arguments:
70
+ subparser.add_argument(*(argument.args), **(argument.kwargs))
71
+ subparser.set_defaults(fn=command.callback)
72
+
73
+ def add_argument(self, *args, **kwargs):
74
+ self.parser.add_argument(*args, **kwargs)
75
+
76
+ def use_logging(self, format):
77
+ verbose = '--verbose' in sys.argv[1:] or '-v' in sys.argv[1:]
78
+ logging.basicConfig(level=logging.DEBUG if verbose else logging.INFO,
79
+ format="[%(levelname)s] %(message)s")
80
+ self.parser.add_argument('--verbose', '-v',
81
+ action='store_true',
82
+ default=False,
83
+ help="show verbose output")
84
+
85
+ def run(self):
86
+ options = self.parser.parse_args()
87
+ if 'fn' not in options:
88
+ logging.error("No command specified.")
89
+ exit(1)
90
+ options.fn(options)
@@ -0,0 +1,57 @@
1
+ Metadata-Version: 2.1
2
+ Name: fastcommand
3
+ Version: 0.1.6
4
+ Author-email: Jason Morley <hello@jbmorley.co.uk>
5
+ License: MIT License
6
+
7
+ Copyright (c) 2021-2024 Jason Morley
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ of this software and associated documentation files (the "Software"), to deal
11
+ in the Software without restriction, including without limitation the rights
12
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ copies of the Software, and to permit persons to whom the Software is
14
+ furnished to do so, subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in all
17
+ copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ SOFTWARE.
26
+
27
+ Description-Content-Type: text/markdown
28
+ License-File: LICENSE
29
+
30
+ # fastcommand
31
+
32
+ Python module for defining multi-command cli programs
33
+
34
+ ## Description
35
+
36
+ The `fastcommand` module is a lightweight wrapper over `argparse` which aims to make it easier to write multi-command cli programs and utilities. It does so by providing convenience decorators that allow for quickly defining sub-commands.
37
+
38
+ ## Usage
39
+
40
+ ```python
41
+ import fastcommand
42
+
43
+
44
+ @fastcommand.command("hello", help="say hello")
45
+ def command_hello(options):
46
+ print("Hello, World!")
47
+
48
+
49
+ def main():
50
+ cli = fastcommand.CommandParser(description="Simple fastcommand example.")
51
+ cli.use_logging(format="[%(levelname)s] %(message)s")
52
+ cli.run()
53
+
54
+
55
+ if __name__ == "__main__":
56
+ main()
57
+ ```
@@ -0,0 +1,10 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ setup.py
5
+ fastcommand/__init__.py
6
+ fastcommand/main.py
7
+ fastcommand.egg-info/PKG-INFO
8
+ fastcommand.egg-info/SOURCES.txt
9
+ fastcommand.egg-info/dependency_links.txt
10
+ fastcommand.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ fastcommand
@@ -0,0 +1,13 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0", "wheel"]
3
+ build-backend = "setuptools.build_meta:__legacy__"
4
+
5
+ [project]
6
+ name = "fastcommand"
7
+ readme = "README.md"
8
+ license = {file = "LICENSE"}
9
+ authors = [
10
+ {name = "Jason Morley", email = "hello@jbmorley.co.uk"}
11
+ ]
12
+ dependencies = []
13
+ dynamic = ["version"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env python3
2
+
3
+ # Copyright (c) 2021-2024 Jason Morley
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.
22
+
23
+ import os
24
+
25
+ from setuptools import setup
26
+
27
+
28
+ setup(version=os.environ["VERSION"] if "VERSION" in os.environ else "0.0.0")