Skip to content

Commit

Permalink
Initial extraction from my target project ecmcli.
Browse files Browse the repository at this point in the history
  • Loading branch information
mayfield committed Aug 25, 2015
0 parents commit 3842251
Show file tree
Hide file tree
Showing 14 changed files with 807 additions and 0 deletions.
54 changes: 54 additions & 0 deletions .gitignore
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/

21 changes: 21 additions & 0 deletions LICENSE
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.
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include README.md
include LICENSE
88 changes: 88 additions & 0 deletions README.md
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
```
28 changes: 28 additions & 0 deletions examples/hello_world.py
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)
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[metadata]
description-file = README.md
42 changes: 42 additions & 0 deletions setup.py
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',
]
)
16 changes: 16 additions & 0 deletions shellish/__init__.py
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)
Loading

0 comments on commit 3842251

Please sign in to comment.