Handle missing configuration file.
- added example config
This commit is contained in:
parent
5149c97150
commit
3788324fbe
|
@ -0,0 +1,2 @@
|
||||||
|
root_directory: "/services/docker"
|
||||||
|
compose_executable: "/usr/bin/docker-compose"
|
19
doxy/cli.py
19
doxy/cli.py
|
@ -8,31 +8,34 @@ from rich.tree import Tree
|
||||||
from doxy import services
|
from doxy import services
|
||||||
from doxy.config import Config
|
from doxy.config import Config
|
||||||
|
|
||||||
|
try:
|
||||||
|
CONFIG = Config()
|
||||||
|
CONFIG.load()
|
||||||
|
except FileNotFoundError as exc:
|
||||||
|
click.echo(exc, sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
@click.group()
|
@click.group()
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def main(ctx):
|
def main(ctx):
|
||||||
ctx.ensure_object(dict)
|
ctx.ensure_object(dict)
|
||||||
config = Config()
|
ctx.obj["CONFIG"] = CONFIG
|
||||||
config.load()
|
|
||||||
ctx.obj["CONFIG"] = config
|
|
||||||
|
|
||||||
|
|
||||||
@click.command()
|
@click.command()
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def list(ctx):
|
def list(ctx):
|
||||||
tree = Tree("[bold]Available Services")
|
tree = Tree("[bold]Available Services")
|
||||||
for service in services.find_services(Path(ctx.obj["CONFIG"].root_directory)):
|
for service in services.find_services(Path(CONFIG.root_directory)):
|
||||||
tree.add(service)
|
tree.add(service)
|
||||||
print(tree)
|
print(tree)
|
||||||
|
|
||||||
|
|
||||||
def complete_service_name(ctx, param, incomplete):
|
def complete_service_name(ctx, param, incomplete):
|
||||||
config = Config()
|
|
||||||
config.load()
|
|
||||||
return [
|
return [
|
||||||
k
|
k
|
||||||
for k in services.find_services(Path(config.root_directory))
|
for k in services.find_services(Path(CONFIG.root_directory))
|
||||||
if k.startswith(incomplete)
|
if k.startswith(incomplete)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -48,6 +51,7 @@ def edit(ctx, service):
|
||||||
click.edit(filename=Path(compose_file))
|
click.edit(filename=Path(compose_file))
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
click.echo(f"Service `{service}' not found", sys.stderr)
|
click.echo(f"Service `{service}' not found", sys.stderr)
|
||||||
|
ctx.abort()
|
||||||
|
|
||||||
|
|
||||||
@click.command()
|
@click.command()
|
||||||
|
@ -62,6 +66,7 @@ def control(ctx, service, command):
|
||||||
services.docker_compose_command(command, compose_file)
|
services.docker_compose_command(command, compose_file)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
click.echo(f"Service `{service}' not found", sys.stderr)
|
click.echo(f"Service `{service}' not found", sys.stderr)
|
||||||
|
ctx.abort()
|
||||||
|
|
||||||
|
|
||||||
main.add_command(list)
|
main.add_command(list)
|
||||||
|
|
Loading…
Reference in New Issue