basic json config-only command

pull/74/head
Mallory Hancock 2019-08-27 12:12:26 -07:00
parent fcd456ea52
commit eee71ad774
2 changed files with 41 additions and 0 deletions

37
pinhook/cli.py 100644
View File

@ -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()

View File

@ -91,6 +91,10 @@ setup(
author_email=EMAIL, author_email=EMAIL,
url=URL, url=URL,
packages=['pinhook'], packages=['pinhook'],
entry_points={
'console_scripts':
['pinhook=pinhook.cli:cli']
},
install_requires=REQUIRED, install_requires=REQUIRED,
include_package_data=True, include_package_data=True,
license='MIT', license='MIT',