add settings command
This commit is contained in:
parent
77df7ece34
commit
5dd0096826
1 changed files with 30 additions and 5 deletions
|
@ -3,16 +3,41 @@ from synclean.api.synapse import SynapseApiClient
|
||||||
from synclean.config.settings import SettingsManager
|
from synclean.config.settings import SettingsManager
|
||||||
from synclean.cli.room_commands import room
|
from synclean.cli.room_commands import room
|
||||||
from synclean.cli.user_commands import user
|
from synclean.cli.user_commands import user
|
||||||
|
from synclean.models.config import SynapseConfig
|
||||||
|
|
||||||
pass_api = click.make_pass_decorator(SynapseApiClient)
|
pass_api = click.make_pass_decorator(SynapseApiClient)
|
||||||
|
|
||||||
@click.group()
|
@click.group(invoke_without_command=True)
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def cli(ctx):
|
def cli(ctx):
|
||||||
"""Synclean CLI."""
|
"""Synclean CLI."""
|
||||||
settings = SettingsManager()
|
settings_manager = SettingsManager()
|
||||||
config = settings.load_config()
|
config = settings_manager.load_config()
|
||||||
ctx.obj = SynapseApiClient(config)
|
ctx.obj = SynapseApiClient(config) if config else None
|
||||||
|
|
||||||
|
if ctx.invoked_subcommand and ctx.invoked_subcommand != "settings" and not config:
|
||||||
|
click.echo("Config file not found. Creating it...")
|
||||||
|
homeserver = click.prompt("Homeserver URL", type=str)
|
||||||
|
access_token = click.prompt("Access token", type=str, hide_input=True)
|
||||||
|
new_config = SynapseConfig(homeserver, access_token)
|
||||||
|
settings_manager.save_config(new_config)
|
||||||
|
ctx.obj = SynapseApiClient(new_config)
|
||||||
|
|
||||||
|
|
||||||
|
@cli.command("settings", help="Manage Synapse settings.")
|
||||||
|
def settings():
|
||||||
|
settings_manager = SettingsManager()
|
||||||
|
config = settings_manager.load_config()
|
||||||
|
if config is not None:
|
||||||
|
click.echo(f"Homeserver: {config.homeserver}")
|
||||||
|
click.echo(f"Access Token: {'SET' if config.access_token else 'UNSET'}")
|
||||||
|
else:
|
||||||
|
click.echo("Config file not found. Creating it...")
|
||||||
|
homeserver = click.prompt("Homeserver URL", type=str)
|
||||||
|
access_token = click.prompt("Access token", type=str, hide_input=True)
|
||||||
|
settings_manager.save_config(SynapseConfig(homeserver, access_token))
|
||||||
|
click.echo("Config file created.")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
cli.add_command(room)
|
cli.add_command(room)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue