Skip to content

Commit

Permalink
apio install: update --list
Browse files Browse the repository at this point in the history
  • Loading branch information
Obijuan committed Mar 14, 2024
1 parent 066167a commit 5094878
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
"type": "debugpy",
"request": "launch",
"program": "${file}",
"args": ["install", "examples"],
"args": ["install", "-l"],
"console": "internalConsole",
"justMyCode": true,
//-- Change to the folder with the example to test
Expand Down
2 changes: 1 addition & 1 deletion apio/managers/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def list_examples(self):
# -- as the terminal
line = "─" * terminal_width

# -- Prin the header
# -- Print the header
click.echo()
click.echo(line)

Expand Down
74 changes: 35 additions & 39 deletions apio/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,56 +216,52 @@ def list_packages(self, installed=True, notinstalled=True):
# Classify packages
installed_packages, notinstalled_packages = self.get_packages()

# Print tables
# -- Calculate the terminal width
terminal_width, _ = shutil.get_terminal_size()

if installed and installed_packages:
# - Print installed packages table
click.echo("\nInstalled packages:\n")
# -- String with a horizontal line with the same width
# -- as the terminal
line = "─" * terminal_width
dline = "═" * terminal_width

package_list_tpl = "{name:20} {description:30} {version:<8}"
if installed and installed_packages:

click.echo("-" * terminal_width)
click.echo(
package_list_tpl.format(
name=click.style("Name", fg="cyan"),
version="Version",
description="Description",
)
)
click.echo("-" * terminal_width)
# ------- Print installed packages table
# -- Print the header
click.echo()
click.echo(dline)
click.echo("Installed packages:")
click.echo(dline)

for package in installed_packages:
click.echo(
package_list_tpl.format(
name=click.style(package.get("name"), fg="cyan"),
version=package.get("version"),
description=package.get("description"),
)
)

if notinstalled and notinstalled_packages:
# - Print not installed packages table
click.echo("\nNot installed packages:\n")
name = click.style(f"{package['name']}", fg="cyan", bold=True)
version = package["version"]
description = package["description"]

package_list_tpl = "{name:20} {description:30}"
click.secho(f"{name} {version}")
click.secho(f" {description}")
click.echo(line)

click.echo("-" * terminal_width)
click.echo(
package_list_tpl.format(
name=click.style("Name", fg="yellow"),
description="Description",
)
)
click.echo("-" * terminal_width)
click.echo()

if notinstalled and notinstalled_packages:

# ------ Print not installed packages table
# -- Print the header
click.echo()
click.echo(dline)
click.echo("Not installed packages:")
click.echo(dline)
click.echo("Name Description")
click.echo(line)

for package in notinstalled_packages:
click.echo(
package_list_tpl.format(
name=click.style(package.get("name"), fg="yellow"),
description=package.get("description"),
)
)

name = click.style(f"{package['name']}", fg="yellow")
description = package["description"]
click.echo(f"{name} {description}")
click.echo(line)

click.echo("\n")

Expand Down

0 comments on commit 5094878

Please sign in to comment.