mirror of https://github.com/openspug/spug
reg cmd with desc - maintain together if so ..
parent
8c82a4af7a
commit
796208d15f
|
@ -5,6 +5,7 @@ import sys
|
||||||
import os
|
import os
|
||||||
|
|
||||||
commands = {}
|
commands = {}
|
||||||
|
commands_desc = {}
|
||||||
|
|
||||||
|
|
||||||
# 工具函数
|
# 工具函数
|
||||||
|
@ -26,9 +27,10 @@ def check_input_username(username):
|
||||||
|
|
||||||
|
|
||||||
# 注册命令
|
# 注册命令
|
||||||
def registry_command(cmd_str):
|
def registry_command(cmd_str, cmd_desc=''):
|
||||||
def decorate(func):
|
def decorate(func):
|
||||||
commands[cmd_str] = func
|
commands[cmd_str] = func
|
||||||
|
commands_desc[cmd_str] = cmd_desc
|
||||||
|
|
||||||
@wraps(func)
|
@wraps(func)
|
||||||
def wrapper(*args, **kwargs):
|
def wrapper(*args, **kwargs):
|
||||||
|
@ -37,7 +39,7 @@ def registry_command(cmd_str):
|
||||||
return decorate
|
return decorate
|
||||||
|
|
||||||
|
|
||||||
@registry_command('init_db')
|
@registry_command('init_db', '初始化数据库')
|
||||||
def init_db():
|
def init_db():
|
||||||
from public import db
|
from public import db
|
||||||
from config import BASE_DIR
|
from config import BASE_DIR
|
||||||
|
@ -64,7 +66,7 @@ def init_db():
|
||||||
create_admin()
|
create_admin()
|
||||||
|
|
||||||
|
|
||||||
@registry_command('create_admin')
|
@registry_command('create_admin', '创建管理员账户')
|
||||||
def create_admin():
|
def create_admin():
|
||||||
from apps.account.models import User
|
from apps.account.models import User
|
||||||
|
|
||||||
|
@ -84,7 +86,7 @@ def create_admin():
|
||||||
print('创建管理员账户成功!')
|
print('创建管理员账户成功!')
|
||||||
|
|
||||||
|
|
||||||
@registry_command('enable_admin')
|
@registry_command('enable_admin', '启用管理员账户,用于登录失败次数过多账户被禁用时使用')
|
||||||
def enable_admin():
|
def enable_admin():
|
||||||
from apps.account.models import User
|
from apps.account.models import User
|
||||||
|
|
||||||
|
@ -94,14 +96,14 @@ def enable_admin():
|
||||||
|
|
||||||
|
|
||||||
def print_usage():
|
def print_usage():
|
||||||
print('''
|
cmd_desc_str = '''
|
||||||
usage: %s <command>
|
usage: %s <command>
|
||||||
|
|
||||||
command:
|
command:
|
||||||
init_db 初始化数据库
|
'''
|
||||||
create_admin 创建管理员账户
|
for k in commands_desc.keys():
|
||||||
enable_admin 启用管理员账户,用于登录失败次数过多账户被禁用时使用
|
cmd_desc_str += '\t{0}\n\t\t-- {1}\n'.format(str(k), str(commands_desc.get(k) if commands_desc.get(k) else ''))
|
||||||
''' % sys.argv[0])
|
print(cmd_desc_str % sys.argv[0])
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in New Issue