From eee71ad774ce2bc7618e1e8680bf09cc023f15f6 Mon Sep 17 00:00:00 2001 From: Mallory Hancock Date: Tue, 27 Aug 2019 12:12:26 -0700 Subject: [PATCH] basic json config-only command --- pinhook/cli.py | 37 +++++++++++++++++++++++++++++++++++++ setup.py | 4 ++++ 2 files changed, 41 insertions(+) create mode 100644 pinhook/cli.py diff --git a/pinhook/cli.py b/pinhook/cli.py new file mode 100644 index 0000000..e075cc2 --- /dev/null +++ b/pinhook/cli.py @@ -0,0 +1,37 @@ +import json + +import click +from .bot import Bot +from marshmallow import Schema, fields, validate, INCLUDE + +class Config(Schema): + nickname = fields.Str(required=True) + channels = fields.List(fields.Str(), required=True) + server = fields.Str(required=True) + port = fields.Int() + ops = fields.List(fields.Str()) + ssl_required = fields.Bool() + plugin_dir = fields.Str() + ns_pass = fields.Str() + log_level = fields.Str(validate=validate.OneOf(['debug', 'warn', 'info', 'off', 'error'])) + server_pass = fields.Str() + + class Meta: + unknown = INCLUDE + +def read_conf(config): + schema = Config() + if config.name.endswith('.json'): + to_json = json.loads(config.read()) + output = schema.load(to_json) + return output + else: + raise click.BadArgumentUsage("Only json files at this time") + +@click.command() +@click.argument('config', type=click.File('rb')) +def cli(config): + config = read_conf(config) + bot = Bot(**config) + bot.start() + diff --git a/setup.py b/setup.py index 63bda35..6fed8c6 100755 --- a/setup.py +++ b/setup.py @@ -91,6 +91,10 @@ setup( author_email=EMAIL, url=URL, packages=['pinhook'], + entry_points={ + 'console_scripts': + ['pinhook=pinhook.cli:cli'] + }, install_requires=REQUIRED, include_package_data=True, license='MIT',