return values

This commit is contained in:
Jörn-Michael Miehe 2020-08-17 15:00:05 +02:00
parent 2acbc1c534
commit 11dafb0db6
9 changed files with 42 additions and 19 deletions

View file

@ -36,13 +36,14 @@ class Runner:
logging.debug(f"Running '{cmd}' with args: {args}") logging.debug(f"Running '{cmd}' with args: {args}")
try: try:
cmd.run(self, LoadedConfig.get(), args) result = cmd.run(self, LoadedConfig.get(), args)
except KeyboardInterrupt: except KeyboardInterrupt:
print() print()
logging.warning(f"'{cmd}' aborted, inputs may have been discarded.") logging.warning(f"'{cmd}' aborted, inputs may have been discarded.")
result = False
return True return result
# command not found # command not found
logging.error(f"kiwi command '{command}' unknown") logging.error(f"kiwi command '{command}' unknown")

View file

@ -23,3 +23,5 @@ class CmdCommand(ProjectCommand):
# run with split compose_cmd argument # run with split compose_cmd argument
DockerCommand('docker-compose').run(config, args, shlex.split(args.compose_cmd)) DockerCommand('docker-compose').run(config, args, shlex.split(args.compose_cmd))
return True

View file

@ -24,9 +24,10 @@ class DownCommand(ServiceCommand):
for project_name in list_projects(config): for project_name in list_projects(config):
args.projects = project_name args.projects = project_name
runner.run('down') runner.run('down')
return else:
return False
if 'services' in args and args.services: elif 'services' in args and args.services:
# "down" for service(s) inside project # "down" for service(s) inside project
logging.info(f"Bringing down services {args.services} in project '{get_project_name(args)}'") logging.info(f"Bringing down services {args.services} in project '{get_project_name(args)}'")
@ -44,3 +45,5 @@ class DownCommand(ServiceCommand):
DockerCommand('docker-compose').run( DockerCommand('docker-compose').run(
config, args, ['down'] config, args, ['down']
) )
return True

View file

@ -65,3 +65,4 @@ class InitCommand(SubCommand):
user_input(config, 'network:cidr', "Enter CIDR block for local docker network") user_input(config, 'network:cidr', "Enter CIDR block for local docker network")
config.save() config.save()
return True

View file

@ -35,3 +35,5 @@ class LogsCommand(ServiceCommand):
DockerCommand('docker-compose').run(config, args, compose_cmd) DockerCommand('docker-compose').run(config, args, compose_cmd)
else: else:
DockerCommand('docker-compose').run_less(config, args, compose_cmd) DockerCommand('docker-compose').run_less(config, args, compose_cmd)
return True

View file

@ -31,7 +31,7 @@ class NetUpCommand(SubCommand):
def run(self, runner, config, args): def run(self, runner, config, args):
if _find_net(config, args): if _find_net(config, args):
logging.info(f"Network '{config['network:name']}' already exists") logging.info(f"Network '{config['network:name']}' already exists")
return return True
try: try:
DockerCommand('docker').run( DockerCommand('docker').run(
@ -49,6 +49,9 @@ class NetUpCommand(SubCommand):
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
logging.error(f"Error creating network '{config['network:name']}'") logging.error(f"Error creating network '{config['network:name']}'")
return False
return True
class NetDownCommand(SubCommand): class NetDownCommand(SubCommand):
@ -63,18 +66,22 @@ class NetDownCommand(SubCommand):
def run(self, runner, config, args): def run(self, runner, config, args):
if not _find_net(config, args): if not _find_net(config, args):
logging.info(f"Network '{config['network:name']}' already removed") logging.info(f"Network '{config['network:name']}' already removed")
return return True
try: try:
if are_you_sure("This will bring down this instance's hub network!"): if are_you_sure("This will bring down this instance's hub network!"):
runner.run('down') if runner.run('down'):
DockerCommand('docker').run(
DockerCommand('docker').run( config, args,
config, args, ['network', 'rm', config['network:name']],
['network', 'rm', config['network:name']], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL )
) logging.info(f"Network '{config['network:name']}' removed")
logging.info(f"Network '{config['network:name']}' removed") else:
return False
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
logging.error(f"Error removing network '{config['network:name']}'") logging.error(f"Error removing network '{config['network:name']}'")
return False
return True

View file

@ -91,3 +91,6 @@ class ShCommand(ServiceCommand):
DockerCommand('docker-compose').run( DockerCommand('docker-compose').run(
config, args, [*compose_cmd, shell] config, args, [*compose_cmd, shell]
) )
return True
return False

View file

@ -13,3 +13,4 @@ class ShowCommand(SubCommand):
def run(self, runner, config, args): def run(self, runner, config, args):
print(config) print(config)
return True

View file

@ -30,7 +30,10 @@ class UpCommand(ServiceCommand):
else: else:
logging.info(f"Bringing up project '{get_project_name(args)}'") logging.info(f"Bringing up project '{get_project_name(args)}'")
runner.run('net-up') if runner.run('net-up'):
DockerCommand('docker-compose').run( DockerCommand('docker-compose').run(
config, args, ['up', '-d', *args.services] config, args, ['up', '-d', *args.services]
) )
return True
return False