-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial extraction from my target project ecmcli.
- Loading branch information
0 parents
commit 3842251
Showing
14 changed files
with
807 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
env/ | ||
bin/ | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.coverage | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
|
||
# Translations | ||
*.mo | ||
|
||
# Mr Developer | ||
.mr.developer.cfg | ||
.project | ||
.pydevproject | ||
|
||
# Rope | ||
.ropeproject | ||
|
||
# Django stuff: | ||
*.log | ||
*.pot | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2015 Justin Mayfield | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
include README.md | ||
include LICENSE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
shellish - Framework for creating heavy a shell-ish CLI. | ||
=========== | ||
|
||
This module combines the Python standard library modules argparse and cmd | ||
to provided a unified way to make cli programs that can also be interactive | ||
when invoked in "shell" mode. | ||
|
||
The main benefit to using this package is streamlined command hierarchy when | ||
you want to have rich set of subcommands along with a pretty powerful tab | ||
completion layer that parses argparse arguments automagically. | ||
|
||
Requirements | ||
-------- | ||
|
||
* None more black! | ||
|
||
|
||
Installation | ||
-------- | ||
|
||
python3 ./setup.py build | ||
python3 ./setup.py install | ||
|
||
|
||
Compatibility | ||
-------- | ||
|
||
* Python 3.4+ | ||
|
||
|
||
TODO | ||
-------- | ||
|
||
* Documentation | ||
* Documentation | ||
* Documentation | ||
|
||
|
||
Getting Started | ||
-------- | ||
|
||
TBD | ||
|
||
|
||
Examples | ||
-------- | ||
|
||
**Hello World** | ||
|
||
A requisite Hello World.. | ||
|
||
```python | ||
import shellish | ||
|
||
|
||
class Hello(shellish.Command): | ||
""" I am a required docstring used to document the --help output! """ | ||
|
||
name = 'hello' | ||
|
||
def __init__(self, *args, **kwargs): | ||
self.add_subcommand(World, default=True) | ||
|
||
def run(self, args): | ||
shellish.Shell(self).cmdloop() | ||
|
||
|
||
class World(shellish.Command): | ||
""" Say something. """ | ||
|
||
name = 'world' | ||
|
||
def run(self, args): | ||
print('Hello World') | ||
|
||
|
||
if __name__ == '__main__': | ||
root = Hello() | ||
args = root.argparser.parse_args() | ||
try: | ||
root.invoke(args) | ||
except KeyboardInterrupt: | ||
sys.exit(1) | ||
``` | ||
|
||
```bash | ||
python3 ./hello.py hello world | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import shellish | ||
|
||
class Hello(shellish.Command): | ||
""" I am a required docstring used to document the --help output! """ | ||
|
||
name = 'hello' | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self.add_subcommand(World, default=True) | ||
|
||
def run(self, args): | ||
shellish.Shell(self).cmdloop() | ||
|
||
|
||
class World(shellish.Command): | ||
""" Say something. """ | ||
|
||
name = 'world' | ||
|
||
def run(self, args): | ||
print('Hello World') | ||
|
||
|
||
if __name__ == '__main__': | ||
root = Hello() | ||
args = root.argparser.parse_args() | ||
root.invoke(args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[metadata] | ||
description-file = README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/usr/bin/env python | ||
|
||
from setuptools import setup, find_packages | ||
|
||
README = 'README.md' | ||
|
||
def long_desc(): | ||
try: | ||
import pypandoc | ||
except ImportError: | ||
with open(README) as f: | ||
return f.read() | ||
else: | ||
return pypandoc.convert(README, 'rst') | ||
|
||
setup( | ||
name='shellish', | ||
version='0.0.1', | ||
description='A command line shell framework', | ||
author='Justin Mayfield', | ||
author_email='[email protected]', | ||
url='https://github.com/mayfield/shellish/', | ||
license='MIT', | ||
long_description=long_desc(), | ||
packages=find_packages(), | ||
install_requires=[], | ||
test_suite='test', | ||
classifiers=[ | ||
'Development Status :: 1 - Planning', | ||
#'Development Status :: 2 - Pre-Alpha', | ||
#'Development Status :: 3 - Alpha', | ||
#'Development Status :: 4 - Beta', | ||
#'Development Status :: 5 - Production/Stable', | ||
#'Development Status :: 6 - Mature', | ||
'Intended Audience :: Developers', | ||
'License :: OSI Approved :: MIT License', | ||
'Operating System :: OS Independent', | ||
'Programming Language :: Python', | ||
'Topic :: Software Development :: Libraries', | ||
'Topic :: System :: Shells', | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
""" | ||
Public interface. | ||
""" | ||
|
||
from . import shell, completer, command | ||
|
||
|
||
def export(module, symbol): | ||
globals()[symbol] = getattr(module, symbol) | ||
|
||
for x in shell.__public__: | ||
export(shell, x) | ||
for x in completer.__public__: | ||
export(completer, x) | ||
for x in command.__public__: | ||
export(command, x) |
Oops, something went wrong.