Skip to content

Commit

Permalink
feat(chart): adds spinner and refactors code
Browse files Browse the repository at this point in the history
  • Loading branch information
pallabpain committed Aug 3, 2023
1 parent e0621dc commit ff28002
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 25 deletions.
7 changes: 4 additions & 3 deletions riocli/chart/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2022 Rapyuta Robotics
# Copyright 2023 Rapyuta Robotics
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -19,13 +19,14 @@
from riocli.chart.info import info_chart
from riocli.chart.list import list_charts
from riocli.chart.search import search_chart
from riocli.constants import Colors


@click.group(
invoke_without_command=False,
cls=HelpColorsGroup,
help_headers_color='yellow',
help_options_color='green',
help_headers_color=Colors.YELLOW,
help_options_color=Colors.GREEN,
)
def chart() -> None:
"""
Expand Down
9 changes: 5 additions & 4 deletions riocli/chart/apply.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2022 Rapyuta Robotics
# Copyright 2023 Rapyuta Robotics
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -17,13 +17,14 @@

from riocli.chart.chart import Chart
from riocli.chart.util import find_chart
from riocli.constants import Colors


@click.command(
'apply',
cls=HelpColorsCommand,
help_headers_color='yellow',
help_options_color='green',
help_headers_color=Colors.YELLOW,
help_options_color=Colors.GREEN,
help='Apply a new Rapyuta Chart in the Project',
)
@click.option('--dryrun', '-d', is_flag=True, default=False,
Expand Down Expand Up @@ -54,7 +55,7 @@ def apply_chart(
if len(versions) > 1:
click.secho(
'More than one charts are available, please specify the version!',
fg='red')
fg=Colors.RED)

chart = Chart(**versions[0])
chart.apply_chart(values, secrets, dryrun=dryrun, workers=workers,
Expand Down
5 changes: 3 additions & 2 deletions riocli/chart/chart.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2022 Rapyuta Robotics
# Copyright 2023 Rapyuta Robotics
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -20,6 +20,7 @@
from munch import Munch

from riocli.apply import apply, delete
from riocli.constants import Colors


class Chart(Munch):
Expand Down Expand Up @@ -66,7 +67,7 @@ def delete_chart(
def download_chart(self):
self._create_temp_directory()
click.secho('Downloading {}:{} chart in {}'.format(
self.name, self.version, self.tmp_dir.name), fg='cyan')
self.name, self.version, self.tmp_dir.name), fg=Colors.CYAN)
chart_filepath = Path(self.tmp_dir.name, self._chart_filename())

with open(chart_filepath, 'wb') as f:
Expand Down
9 changes: 5 additions & 4 deletions riocli/chart/delete.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2022 Rapyuta Robotics
# Copyright 2023 Rapyuta Robotics
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -16,13 +16,14 @@

from riocli.chart.chart import Chart
from riocli.chart.util import find_chart
from riocli.constants import Colors


@click.command(
'delete',
cls=HelpColorsCommand,
help_headers_color='yellow',
help_options_color='green',
help_headers_color=Colors.YELLOW,
help_options_color=Colors.GREEN,
help='Delete the Rapyuta Chart from the Project',
)
@click.option('--dryrun', '-d', is_flag=True, default=False,
Expand All @@ -47,7 +48,7 @@ def delete_chart(
versions = find_chart(chart)
if len(versions) > 1:
click.secho('More than one charts are available, '
'please specify the version!', fg='yellow')
'please specify the version!', fg=Colors.YELLOW)

chart = Chart(**versions[0])
chart.delete_chart(values=values, secrets=secrets,
Expand Down
7 changes: 4 additions & 3 deletions riocli/chart/info.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2022 Rapyuta Robotics
# Copyright 2023 Rapyuta Robotics
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -16,14 +16,15 @@
from click_help_colors import HelpColorsCommand

from riocli.chart.util import find_chart
from riocli.constants import Colors
from riocli.utils import dump_all_yaml


@click.command(
'info',
cls=HelpColorsCommand,
help_headers_color='yellow',
help_options_color='green',
help_headers_color=Colors.YELLOW,
help_options_color=Colors.GREEN,
help='Describe the available chart with versions',
)
@click.argument('chart', type=str)
Expand Down
7 changes: 4 additions & 3 deletions riocli/chart/list.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2022 Rapyuta Robotics
# Copyright 2023 Rapyuta Robotics
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -17,13 +17,14 @@
from munch import munchify

from riocli.chart.util import fetch_index, print_chart_entries
from riocli.constants import Colors


@click.command(
'list',
cls=HelpColorsCommand,
help_headers_color='yellow',
help_options_color='green',
help_headers_color=Colors.YELLOW,
help_options_color=Colors.GREEN,
)
@click.option('-w', '--wide', is_flag=True, default=False,
help='Print more details')
Expand Down
23 changes: 17 additions & 6 deletions riocli/chart/search.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2022 Rapyuta Robotics
# Copyright 2023 Rapyuta Robotics
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -14,21 +14,32 @@

import click
from click_help_colors import HelpColorsCommand
from yaspin.api import Yaspin

from riocli.chart.util import find_chart, print_chart_entries
from riocli.constants import Colors, Symbols
from riocli.utils.spinner import with_spinner


@click.command(
'search',
cls=HelpColorsCommand,
help_headers_color='yellow',
help_options_color='green',
help_headers_color=Colors.YELLOW,
help_options_color=Colors.GREEN,
help='Search for available charts in the repository',
)
@click.option('-w', '--wide', is_flag=True, default=False,
help='Print more details')
@click.argument('chart', type=str)
def search_chart(chart: str, wide: bool = False) -> None:
@with_spinner(text="Searching for chart...")
def search_chart(chart: str, wide: bool = False,
spinner: Yaspin = None) -> None:
"""Search for a chart in the chart repo."""
versions = find_chart(chart)
print_chart_entries(versions, wide=wide)
try:
versions = find_chart(chart)
with spinner.hidden():
print_chart_entries(versions, wide=wide)
except Exception as e:
spinner.text = click.style(str(e), fg=Colors.RED)
spinner.red.fail(Symbols.ERROR)
raise SystemExit(1) from e

0 comments on commit ff28002

Please sign in to comment.