Skip to content

Commit

Permalink
cli: sopel-module show with events and better display
Browse files Browse the repository at this point in the history
  • Loading branch information
Exirel committed Jan 24, 2019
1 parent c3d2370 commit a9e320f
Showing 1 changed file with 35 additions and 26 deletions.
61 changes: 35 additions & 26 deletions sopel/cli/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import unicode_literals, absolute_import, print_function, division

import argparse
import datetime
import imp
import inspect
import os
Expand Down Expand Up @@ -189,56 +190,64 @@ def handle_show(options, settings):
return 1

callables, jobs, shutdowns, urls = module_info
last_modified_display = datetime.datetime.fromtimestamp(
last_modified
).strftime('%Y-%m-%d %H:%M:%S')

print('# Module Information')
print('')
print('Module name: %s' % module_name)
print('Path: %s' % module_path)
print('Last modified at: %s' % last_modified)
print('Last modified at: %s' % last_modified_display)
print('Has shutdown: %s' % ('yes' if shutdowns else 'no'))
print('Has job: %s' % ('yes' if jobs else 'no'))

rule_callables = []
command_callables = []

if callables:
rule_callables = []
print('')
print('# Module Commands')
for command in callables:
if command._docs.keys():
print('')
print('## %s' % ', '.join(command._docs.keys()))
command_callables.append(command)
elif getattr(command, 'rule', None):
# display rules afters normal commands
rule_callables.append(command)
continue
elif getattr(command, 'intents', None):
rule_callables.append(command)
continue
else:
# nothing to display right now
continue

if command_callables:
print('')
print('# Module Commands')

for command in command_callables:
print('')
print('## %s' % ', '.join(command._docs.keys()))

docstring = inspect.cleandoc(
command.__doc__ or 'No documentation provided.'
).splitlines()
for line in docstring:
print('\t%s' % line)

if rule_callables:
if rule_callables:
print('')
print('# Module Rules')

for command in rule_callables:
print('')
print('# Module Rules')

for command in rule_callables:
print('')
for intent in getattr(command, 'intents', []):
print('[INTENT]', intent.pattern)
for rule in getattr(command, 'rule', []):
print(rule.pattern)

docstring = inspect.cleandoc(
command.__doc__ or 'No documentation provided.'
).splitlines()
for line in docstring:
print('\t%s' % line)
for intent in getattr(command, 'intents', []):
print('[INTENT]', intent.pattern)
for rule in getattr(command, 'rule', []):
print(rule.pattern)

for event in getattr(command, 'event', []):
print('[EVENT]', event)

docstring = inspect.cleandoc(
command.__doc__ or 'No documentation provided.'
).splitlines()
for line in docstring:
print('\t%s' % line)

if urls:
print('')
Expand Down

0 comments on commit a9e320f

Please sign in to comment.