basic json config-only command
parent
fcd456ea52
commit
eee71ad774
|
@ -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()
|
||||||
|
|
4
setup.py
4
setup.py
|
@ -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',
|
||||||
|
|
Loading…
Reference in New Issue