mirror of
https://github.com/frappe/bench.git
synced 2024-11-14 09:14:04 +00:00
fix: added aliases for click commands to convert _ seperated commands to
- seperated ones in config group eg: `bench config auto-update on` functions same as `bench config auto_update on`
This commit is contained in:
parent
1f488a8bfd
commit
214a2093eb
@ -1,80 +1,87 @@
|
|||||||
import click, json
|
# imports - standard imports
|
||||||
from bench.config.common_site_config import update_config
|
import ast
|
||||||
|
import json
|
||||||
|
|
||||||
## Config
|
# imports - module imports
|
||||||
## Not DRY
|
from bench.config.common_site_config import update_config, get_config, put_config
|
||||||
@click.group()
|
|
||||||
|
# imports - third party imports
|
||||||
|
import click
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class AliasedGroup(click.Group):
|
||||||
|
def get_command(self, ctx, cmd_name):
|
||||||
|
try:
|
||||||
|
cmd_name = ALIASES[cmd_name].name
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
return super(AliasedGroup, self).get_command(ctx, cmd_name)
|
||||||
|
|
||||||
|
|
||||||
|
@click.group(cls=AliasedGroup, help='Change bench configuration')
|
||||||
def config():
|
def config():
|
||||||
"change bench configuration"
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@click.command('auto_update')
|
|
||||||
|
@click.command('auto_update', help='Enable/Disable auto update for bench')
|
||||||
@click.argument('state', type=click.Choice(['on', 'off']))
|
@click.argument('state', type=click.Choice(['on', 'off']))
|
||||||
def config_auto_update(state):
|
def config_auto_update(state):
|
||||||
"Enable/Disable auto update for bench"
|
|
||||||
state = True if state == 'on' else False
|
state = True if state == 'on' else False
|
||||||
update_config({'auto_update': state})
|
update_config({'auto_update': state})
|
||||||
|
|
||||||
|
|
||||||
@click.command('restart_supervisor_on_update')
|
@click.command('restart_supervisor_on_update', help='Enable/Disable auto restart of supervisor processes')
|
||||||
@click.argument('state', type=click.Choice(['on', 'off']))
|
@click.argument('state', type=click.Choice(['on', 'off']))
|
||||||
def config_restart_supervisor_on_update(state):
|
def config_restart_supervisor_on_update(state):
|
||||||
"Enable/Disable auto restart of supervisor processes"
|
|
||||||
state = True if state == 'on' else False
|
state = True if state == 'on' else False
|
||||||
update_config({'restart_supervisor_on_update': state})
|
update_config({'restart_supervisor_on_update': state})
|
||||||
|
|
||||||
@click.command('restart_systemd_on_update')
|
|
||||||
|
@click.command('restart_systemd_on_update', help='Enable/Disable auto restart of systemd units')
|
||||||
@click.argument('state', type=click.Choice(['on', 'off']))
|
@click.argument('state', type=click.Choice(['on', 'off']))
|
||||||
def config_restart_systemd_on_update(state):
|
def config_restart_systemd_on_update(state):
|
||||||
"Enable/Disable auto restart of systemd units"
|
|
||||||
state = True if state == 'on' else False
|
state = True if state == 'on' else False
|
||||||
update_config({'restart_systemd_on_update': state})
|
update_config({'restart_systemd_on_update': state})
|
||||||
|
|
||||||
@click.command('update_bench_on_update')
|
|
||||||
|
@click.command('update_bench_on_update', help='Enable/Disable bench updates on running bench update')
|
||||||
@click.argument('state', type=click.Choice(['on', 'off']))
|
@click.argument('state', type=click.Choice(['on', 'off']))
|
||||||
def config_update_bench_on_update(state):
|
def config_update_bench_on_update(state):
|
||||||
"Enable/Disable bench updates on running bench update"
|
|
||||||
state = True if state == 'on' else False
|
state = True if state == 'on' else False
|
||||||
update_config({'update_bench_on_update': state})
|
update_config({'update_bench_on_update': state})
|
||||||
|
|
||||||
|
|
||||||
@click.command('dns_multitenant')
|
@click.command('dns_multitenant', help='Enable/Disable bench multitenancy on running bench update')
|
||||||
@click.argument('state', type=click.Choice(['on', 'off']))
|
@click.argument('state', type=click.Choice(['on', 'off']))
|
||||||
def config_dns_multitenant(state):
|
def config_dns_multitenant(state):
|
||||||
"Enable/Disable bench updates on running bench update"
|
|
||||||
state = True if state == 'on' else False
|
state = True if state == 'on' else False
|
||||||
update_config({'dns_multitenant': state})
|
update_config({'dns_multitenant': state})
|
||||||
|
|
||||||
|
|
||||||
@click.command('serve_default_site')
|
@click.command('serve_default_site', help='Configure nginx to serve the default site on port 80')
|
||||||
@click.argument('state', type=click.Choice(['on', 'off']))
|
@click.argument('state', type=click.Choice(['on', 'off']))
|
||||||
def config_serve_default_site(state):
|
def config_serve_default_site(state):
|
||||||
"Configure nginx to serve the default site on port 80"
|
|
||||||
state = True if state == 'on' else False
|
state = True if state == 'on' else False
|
||||||
update_config({'serve_default_site': state})
|
update_config({'serve_default_site': state})
|
||||||
|
|
||||||
|
|
||||||
@click.command('rebase_on_pull')
|
@click.command('rebase_on_pull', help='Rebase repositories on pulling')
|
||||||
@click.argument('state', type=click.Choice(['on', 'off']))
|
@click.argument('state', type=click.Choice(['on', 'off']))
|
||||||
def config_rebase_on_pull(state):
|
def config_rebase_on_pull(state):
|
||||||
"Rebase repositories on pulling"
|
|
||||||
state = True if state == 'on' else False
|
state = True if state == 'on' else False
|
||||||
update_config({'rebase_on_pull': state})
|
update_config({'rebase_on_pull': state})
|
||||||
|
|
||||||
|
|
||||||
@click.command('http_timeout')
|
@click.command('http_timeout', help='Set HTTP timeout')
|
||||||
@click.argument('seconds', type=int)
|
@click.argument('seconds', type=int)
|
||||||
def config_http_timeout(seconds):
|
def config_http_timeout(seconds):
|
||||||
"set http timeout"
|
|
||||||
update_config({'http_timeout': seconds})
|
update_config({'http_timeout': seconds})
|
||||||
|
|
||||||
|
|
||||||
@click.command('set-common-config')
|
@click.command('set-common-config', help='Set value in common config')
|
||||||
@click.option('configs', '-c', '--config', multiple=True, type=(str, str))
|
@click.option('configs', '-c', '--config', multiple=True, type=(str, str))
|
||||||
def set_common_config(configs):
|
def set_common_config(configs):
|
||||||
import ast
|
|
||||||
from bench.config.common_site_config import update_config
|
|
||||||
|
|
||||||
common_site_config = {}
|
common_site_config = {}
|
||||||
for key, value in configs:
|
for key, value in configs:
|
||||||
if value in ("False", "True"):
|
if value in ("False", "True"):
|
||||||
@ -103,10 +110,9 @@ def set_common_config(configs):
|
|||||||
update_config(common_site_config, bench_path='.')
|
update_config(common_site_config, bench_path='.')
|
||||||
|
|
||||||
|
|
||||||
@click.command('remove-common-config')
|
@click.command('remove-common-config', help='Remove specific keys from current bench\'s common config')
|
||||||
@click.argument('keys', nargs=-1)
|
@click.argument('keys', nargs=-1)
|
||||||
def remove_common_config(keys):
|
def remove_common_config(keys):
|
||||||
from bench.config.common_site_config import get_config, put_config
|
|
||||||
common_site_config = get_config('.')
|
common_site_config = get_config('.')
|
||||||
for key in keys:
|
for key in keys:
|
||||||
if key in common_site_config:
|
if key in common_site_config:
|
||||||
@ -124,3 +130,6 @@ config.add_command(config_serve_default_site)
|
|||||||
config.add_command(config_http_timeout)
|
config.add_command(config_http_timeout)
|
||||||
config.add_command(set_common_config)
|
config.add_command(set_common_config)
|
||||||
config.add_command(remove_common_config)
|
config.add_command(remove_common_config)
|
||||||
|
|
||||||
|
# aliases for _ seperated commands to - ones
|
||||||
|
ALIASES = {k.replace('_', '-'):v for k, v in config.commands.items() if '_' in k}
|
||||||
|
Loading…
Reference in New Issue
Block a user