Skip to content

Commit

Permalink
feat: Add new docker compose commands (experimental)
Browse files Browse the repository at this point in the history
  • Loading branch information
xmnlab committed May 16, 2024
1 parent 6b4dca5 commit 7d8e5a2
Show file tree
Hide file tree
Showing 3 changed files with 296 additions and 0 deletions.
1 change: 1 addition & 0 deletions .makim.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ groups:
- task: docker.killall
run: |
sugar build --verbose
sugar ls
sugar build --verbose --group group1 --all
sugar build --verbose --group group1
sugar build --verbose --group group1 --services service1-1
Expand Down
261 changes: 261 additions & 0 deletions src/sugar/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,50 @@ def create_main_group(sugar_app: typer.Typer):
"""
# -- Main commands --

@sugar_app.command()
def attach(
ctx: typer.Context,
service_group: str = Option(
None,
'--service-group',
'--group',
help='Specify the group name of the services you want to use',
),
service: str = Option(
None, help='Set the service for the container call.'
),
options: str = Option(
None,
help=(
'Specify the options for docker-compose command. '
'E.g.: --options -d'
),
),
config_file: str = Option(
str(Path(os.getcwd()) / '.sugar.yaml'),
help='Specify a custom location for the config file.',
is_flag=True,
),
verbose: bool = Option(
False,
'--verbose',
is_flag=True,
is_eager=True,
help='Show the command executed.',
),
):
"""Build or rebuild services."""
args = ctx.params
args['plugin'] = 'main'
args['action'] = 'attach'

if verbose or flags_state['verbose']:
args['verbose'] = True

opts_args: list[Any] = opt_state['options']

Sugar(args, options_args=opts_args).run()

@sugar_app.command()
def build(
ctx: typer.Context,
Expand Down Expand Up @@ -190,6 +234,47 @@ def config(

Sugar(args, options_args=opts_args, cmd_args=cmd_args).run()

@sugar_app.command()
def cp(
ctx: typer.Context,
service_group: str = Option(
None,
'--service-group',
'--group',
help='Specify the group name of the services you want to use',
),
options: str = Option(
None,
help=(
'Specify the options for docker-compose command. '
'E.g.: --options -d'
),
),
config_file: str = Option(
str(Path(os.getcwd()) / '.sugar.yaml'),
help='Specify a custom location for the config file.',
is_flag=True,
),
verbose: bool = Option(
False,
'--verbose',
is_flag=True,
is_eager=True,
help='Show the command executed.',
),
):
"""Build or rebuild services."""
args = ctx.params
args['plugin'] = 'main'
args['action'] = 'cp'

if verbose or flags_state['verbose']:
args['verbose'] = True

opts_args: list[Any] = opt_state['options']

Sugar(args, options_args=opts_args).run()

@sugar_app.command()
def create(
ctx: typer.Context,
Expand Down Expand Up @@ -522,6 +607,45 @@ def logs(

Sugar(args, options_args=opts_args, cmd_args=cmd_args).run()

@sugar_app.command()
def ls(
ctx: typer.Context,
service_group: str = Option(
None,
'--service-group',
'--group',
help='Specify the group name of the services you want to use',
),
options: str = Option(
None,
help='Specify the options for docker-compose command.\
E.g.: --options -d',
),
config_file: str = Option(
str(Path(os.getcwd()) / '.sugar.yaml'),
help='Specify a custom location for the config file.',
is_flag=True,
),
verbose: bool = Option(
False,
'--verbose',
is_flag=True,
is_eager=True,
help='Show the command executed.',
),
):
"""View output from containers."""
args = ctx.params
args['plugin'] = 'main'
args['action'] = 'ls'

if verbose or flags_state['verbose']:
args['verbose'] = True

opts_args: list[Any] = opt_state['options']

Sugar(args, options_args=opts_args).run()

@sugar_app.command()
def pause(
ctx: typer.Context,
Expand Down Expand Up @@ -901,6 +1025,45 @@ def run(

Sugar(args, options_args=opts_args, cmd_args=cmd_args).run()

@sugar_app.command()
def scale(
ctx: typer.Context,
service_group: str = Option(
None,
'--service-group',
'--group',
help='Specify the group name of the services you want to use',
),
options: str = Option(
None,
help='Specify the options for docker-compose command.\
E.g.: --options -d',
),
config_file: str = Option(
str(Path(os.getcwd()) / '.sugar.yaml'),
help='Specify a custom location for the config file.',
is_flag=True,
),
verbose: bool = Option(
False,
'--verbose',
is_flag=True,
is_eager=True,
help='Show the command executed.',
),
):
"""View output from containers."""
args = ctx.params
args['plugin'] = 'main'
args['action'] = 'scale'

if verbose or flags_state['verbose']:
args['verbose'] = True

opts_args: list[Any] = opt_state['options']

Sugar(args, options_args=opts_args).run()

@sugar_app.command()
def start(
ctx: typer.Context,
Expand Down Expand Up @@ -1185,6 +1348,104 @@ def version(

Sugar(args, options_args=opts_args, cmd_args=cmd_args).run()

@sugar_app.command()
def wait(
ctx: typer.Context,
service_group: str = Option(
None,
'--service-group',
'--group',
help='Specify the group name of the services you want to use',
),
services: str = Option(
None,
help="Set the services for the container call.\
Use comma to separate the services's name",
),
options: str = Option(
None,
help='Specify the options for docker-compose command.\
E.g.: --options -d',
),
all: bool = Option(
False,
help='Use all services for the command.',
is_flag=True,
),
config_file: str = Option(
str(Path(os.getcwd()) / '.sugar.yaml'),
help='Specify a custom location for the config file.',
is_flag=True,
),
verbose: bool = Option(
False,
'--verbose',
is_flag=True,
is_eager=True,
help='Show the command executed.',
),
):
"""Stop services."""
args = ctx.params
args['plugin'] = 'main'
args['action'] = 'wait'

if verbose or flags_state['verbose']:
args['verbose'] = True

opts_args: list[Any] = opt_state['options']

Sugar(args, options_args=opts_args).run()

@sugar_app.command()
def watch(
ctx: typer.Context,
service_group: str = Option(
None,
'--service-group',
'--group',
help='Specify the group name of the services you want to use',
),
services: str = Option(
None,
help="Set the services for the container call.\
Use comma to separate the services's name",
),
options: str = Option(
None,
help='Specify the options for docker-compose command.\
E.g.: --options -d',
),
all: bool = Option(
False,
help='Use all services for the command.',
is_flag=True,
),
config_file: str = Option(
str(Path(os.getcwd()) / '.sugar.yaml'),
help='Specify a custom location for the config file.',
is_flag=True,
),
verbose: bool = Option(
False,
'--verbose',
is_flag=True,
is_eager=True,
help='Show the command executed.',
),
):
"""Stop services."""
args = ctx.params
args['plugin'] = 'main'
args['action'] = 'watch'

if verbose or flags_state['verbose']:
args['verbose'] = True

opts_args: list[Any] = opt_state['options']

Sugar(args, options_args=opts_args).run()


def create_ext_group(sugar_app: typer.Typer):
"""
Expand Down
Loading

0 comments on commit 7d8e5a2

Please sign in to comment.