Skip to content
This repository has been archived by the owner on Nov 30, 2023. It is now read-only.

Commit

Permalink
Merge pull request #5 from marksteve/cli
Browse files Browse the repository at this point in the history
Add cli script
  • Loading branch information
emre committed Jul 3, 2013
2 parents b8329e2 + 5228f0f commit a1bace7
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
37 changes: 37 additions & 0 deletions kaptan/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,40 @@ def export(self, handler=None):
handler_class = self.HANDLER_MAP[handler]()

return handler_class.dump(self.configuration_data)


def main():
import argparse
import os
parser = argparse.ArgumentParser(
description='Configuration manager in your pocket')
parser.add_argument('config_file', action='store',
help="file to load config from")
parser.add_argument('--handler', action='store',
help="handler to use (default: guessed from filename)")
parser.add_argument('-e', '--export', action='store', default='json',
help="format to export to")
parser.add_argument('-k', '--key', action='store',
help="config key to get value of")
args = parser.parse_args()
HANDLER_EXT = {
'ini': 'ini',
'conf': 'ini',
'yaml': 'yaml',
'json': 'json',
'py': 'file',
}
handler = (args.handler or
HANDLER_EXT.get(
os.path.splitext(args.config_file)[1][1:],
None
))
if not handler:
raise RuntimeError("Unable to determine handler")
with open(args.config_file) as f:
config = Kaptan(handler=handler)
config.import_config(f.read())
if args.key:
print config.get(args.key)
else:
print config.export(args.export)
9 changes: 7 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from distutils.core import setup
from setuptools import setup

setup(
name='kaptan',
Expand All @@ -9,5 +9,10 @@
author='Emre Yilmaz',
author_email='[email protected]',
description='Configuration Manager',
requires=['PyYAML', ],
install_requires=['PyYAML', ],
entry_points=dict(
console_scripts=[
'kaptan = kaptan:main',
],
),
)

0 comments on commit a1bace7

Please sign in to comment.