-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
104 additions
and
541 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
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
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 |
---|---|---|
|
@@ -20,6 +20,7 @@ def read(fname): | |
'clint2==0.3.2', | ||
'sh==1.08', | ||
'six==1.3.0', | ||
'docopt==0.6.1' | ||
] | ||
|
||
test_requires = [ | ||
|
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
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 |
---|---|---|
@@ -1,107 +1,50 @@ | ||
""" | ||
facio.cli | ||
--------- | ||
# -*- coding: utf-8 -*- | ||
|
||
Prompt user to enter options for Facio, determines how Facio behaves. Options | ||
are split into 3 groups: | ||
- Project Options | ||
- Template Options | ||
- Experimental Options | ||
""" | ||
.. module:: facio.cli | ||
:synopsis: Facio command line entry point and configuration. | ||
""" | ||
|
||
|
||
import optparse | ||
import re | ||
import sys | ||
|
||
from . import __version__ | ||
|
||
from docopt import docopt | ||
from facio import __version__ | ||
|
||
class CLIOptions(object): | ||
|
||
MANDATORY_OPTS = ['project_name', ] | ||
class CLI(object): | ||
""" | ||
Facio. | ||
def __init__(self): | ||
self._parser = optparse.OptionParser( | ||
usage='Usage: %prog -n <project_name> <options>', | ||
version='%prog version {0}'.format(__version__), | ||
description='Facio is a project scaffolding tool origionally ' | ||
'developed for Django and expanded to be framework ' | ||
'agnostic. You can use facio to bootstrap any sort ' | ||
'of project.', | ||
epilog='Example: facio -n hello_world -c --vars foo=bar') | ||
self._add_project_options() | ||
self._add_template_options() | ||
self._add_experimental_options() | ||
self.opts, self.args = self._parser.parse_args() | ||
self._validate() | ||
|
||
def __getattr__(self, name): | ||
opt = getattr(self.opts, name, None) | ||
if not opt is None: | ||
return opt | ||
else: | ||
raise AttributeError | ||
Facio is a project scaffolding tool originally developed for Django and | ||
expanded to be framework agnostic. You can use facio to bootstrap any sort | ||
of project. | ||
def _add_project_options(self): | ||
group = optparse.OptionGroup(self._parser, 'Project Options') | ||
group.add_option('-n', '--name', dest='project_name', | ||
help='The Project Name (Mandatory), only use ' | ||
'alphanumeric chracters and underscores.', | ||
type='string', metavar='<ARG>') | ||
self._parser.add_option_group(group) | ||
Usage: | ||
facio <project_name> [--template <path>|--select] [--vars <variables>] | ||
def _add_template_options(self): | ||
group = optparse.OptionGroup(self._parser, 'Template Options') | ||
group.add_option('-t', '--template', dest='template', action='store', | ||
help='Path to your custom template, absolute paths ' | ||
'only , git repositories can also be specified by ' | ||
'prefixing with git+ for example: git+git@gitbub.com' | ||
'/path/to/repo.git', type='string', metavar='<ARG1>') | ||
group.add_option('-c', '--choose_template', dest='choose_template', | ||
help='If you have more than 1 template defined use ' | ||
'this flag to override the default template, Note: ' | ||
'specifying -t (--template) will mean this ' | ||
'flag is ignored.', action='store_true', | ||
default=False) | ||
group.add_option('-s', '--template_settings_dir', action='store', | ||
help='Template settings directory name', | ||
type='string', metavar='<ARG>') | ||
group.add_option('--vars', dest='variables', action='store', | ||
default=False, help='Custom variables, e.g --vars ' | ||
'hello=world,sky=blue', metavar='<ARG>'), | ||
self._parser.add_option_group(group) | ||
Options: | ||
-h --help Show this help text. | ||
--version Show version. | ||
-t --template <path> Template path, can be repository link | ||
(git+ / hg+) or a template name defined in | ||
~/.facio.cfg. | ||
-s --select Lists templates in ~/.facio.cfg prompting you | ||
to select a template from this list. | ||
--vars <variables> Comma separated key=value pairs of values to be | ||
used in processing templates. | ||
def _add_experimental_options(self): | ||
group = optparse.OptionGroup(self._parser, 'Experimental Options') | ||
group.add_option('-i', '--install', action='store_true', default=False, | ||
help='Install the project onto your path, e.g ' | ||
'python setup.py develop'), | ||
group.add_option('-e', '--venv_create', dest='venv_create', | ||
action='store_true', default=False, | ||
help='Create python virtual environment'), | ||
group.add_option('-p', '--venv_path', dest='venv_path', action='store', | ||
help='Python virtualenv home directory', | ||
type='string', metavar='<ARG>'), | ||
group.add_option('-S', '--venv_use_site_packages', | ||
dest='venv_use_site_packages', action='store_true', | ||
default=False, help='Create python vittual ' | ||
'environment without --no-site-packages'), | ||
group.add_option('-x', '--venv_prefix', dest='venv_prefix', | ||
action='store', | ||
help='Virtual environment name prefix', | ||
type='string', metavar='<ARG>') | ||
self._parser.add_option_group(group) | ||
Example: | ||
facio hello_world -t git+git@github.com:you/django.git --vars foo=bar | ||
""" | ||
|
||
def _validate(self): | ||
self._validate_required() | ||
def __init__(self): | ||
self.arguments = docopt( | ||
self.__doc__, | ||
version='Facio {0}'.format(__version__)) | ||
self._validate_project_name() | ||
|
||
def _validate_required(self): | ||
for opt in self.MANDATORY_OPTS: | ||
if not getattr(self.opts, opt, None): | ||
self._parser.error('A mandatory option is missing, see --help') | ||
|
||
def _validate_project_name(self): | ||
if not re.match('^\w+$', self.opts.project_name): | ||
self._parser.error('Project names can only contain numbers' | ||
'letters and underscores') | ||
if not re.match('^\w+$', self.arguments.get('<project_name>')): | ||
sys.exit('Project names can only contain numbers letters and ' | ||
'underscores') |
Oops, something went wrong.