Skip to content

Commit

Permalink
Merge pull request #452 from linode/dev
Browse files Browse the repository at this point in the history
Release v5.37.0
  • Loading branch information
zliang-akamai authored May 3, 2023
2 parents 0857e40 + fcaaf50 commit 0b915fb
Show file tree
Hide file tree
Showing 17 changed files with 187 additions and 144 deletions.
14 changes: 2 additions & 12 deletions .github/workflows/e2e-suite-pr-command.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,10 @@ jobs:
runs-on: ubuntu-latest
if: ${{ github.event.issue.pull_request }}
steps:
- name: Generate App Installation Token
id: generate_token
uses: tibdex/github-app-token@v1
with:
app_id: ${{ secrets.DX_ACCTEST_APP_ID }}
private_key: ${{ secrets.DX_ACCTEST_PRIV_KEY }}

- name: Slash Command Dispatch
uses: peter-evans/slash-command-dispatch@v1
env:
TOKEN: ${{ steps.generate_token.outputs.token }}
uses: peter-evans/slash-command-dispatch@v3
with:
token: ${{ env.TOKEN }}
reaction-token: ${{ secrets.GITHUB_TOKEN }}
token: ${{ secrets.GITHUB_TOKEN }}
issue-type: pull-request
commands: acctest
named-args: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
python-version: '3.x'

- name: Install Python wheel
run: pip install wheel boto3
run: pip install wheel boto3 mock

- name: Update cert
run: pip install certifi -U
Expand Down
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ clean:
testunit: export LINODE_CLI_TEST_MODE = 1
testunit:
pytest tests/unit
python -m unittest tests/unit/*.py

.PHONY: testint
testint:
Expand Down
13 changes: 13 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ Using an existing config file::

docker run --rm -it -v $HOME/.config/linode-cli:/home/cli/.config/linode-cli linode/cli:latest linodes list

GitHub Actions
^^^^^^^^^^^^^^

The Linode CLI can be automatically installed and authenticated in a GitHub actions environment using
the `Setup Linode CLI`_ GitHub Action::

- name: Install the Linode CLI
uses: linode/action-linode-cli@v1
with:
token: ${{ secrets.LINODE_TOKEN }}

.. _Setup Linode CLI: https://github.com/marketplace/actions/setup-linode-cli

Upgrading
---------

Expand Down
9 changes: 6 additions & 3 deletions linodecli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
from sys import argv

import pkg_resources
from terminaltables import SingleTable
from rich import print as rprint
from rich.table import Table

from linodecli import plugins

Expand Down Expand Up @@ -234,8 +235,10 @@ def main(): # pylint: disable=too-many-branches,too-many-statements
for action, op in cli.ops[parsed.command].items()
]

table = SingleTable([["action", "summary"]] + content)
print(table.table)
table = Table("action", "summary")
for row in content:
table.add_row(*row)
rprint(table)
sys.exit(0)

if parsed.command is not None and parsed.action is not None:
Expand Down
39 changes: 22 additions & 17 deletions linodecli/arg_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

import requests
import yaml
from terminaltables import SingleTable
from rich import print as rprint
from rich.table import Table

from linodecli import plugins

Expand Down Expand Up @@ -233,23 +234,26 @@ def help_with_ops(ops, config):
# commands to manage CLI users (don't call out to API)
print("\nCLI user management commands:")
um_commands = [["configure", "set-user", "show-users"], ["remove-user"]]
table = SingleTable(um_commands)
table.inner_heading_row_border = False
print(table.table)
table = Table(show_header=False)
for cmd in um_commands:
table.add_row(*cmd)
rprint(table)

# commands to manage plugins (don't call out to API)
print("\nCLI Plugin management commands:")
pm_commands = [["register-plugin", "remove-plugin"]]
table = SingleTable(pm_commands)
table.inner_heading_row_border = False
print(table.table)
table = Table(show_header=False)
for cmd in pm_commands:
table.add_row(*cmd)
rprint(table)

# other CLI commands
print("\nOther CLI commands:")
other_commands = [["completion"]]
table = SingleTable(other_commands)
table.inner_heading_row_border = False
print(table.table)
table = Table(show_header=False)
for cmd in other_commands:
table.add_row(*cmd)
rprint(table)

# commands generated from the spec (call the API directly)
print("\nAvailable commands:")
Expand All @@ -261,9 +265,10 @@ def help_with_ops(ops, config):
if content[i + 3 :]:
proc.append(content[i + 3 :])

table = SingleTable(proc)
table.inner_heading_row_border = False
print(table.table)
table = Table(show_header=False)
for cmd in proc:
table.add_row(*cmd)
rprint(table)

# plugins registered to the CLI (do arbitrary things)
if plugins.available(config):
Expand All @@ -278,10 +283,10 @@ def help_with_ops(ops, config):
if plugin_content[i + 3 :]:
plugin_proc.append(plugin_content[i + 3 :])

plugin_table = SingleTable(plugin_proc)
plugin_table.inner_heading_row_border = False

print(plugin_table.table)
plugin_table = Table(show_header=False)
for plugin in plugin_proc:
plugin_table.add_row(*plugin)
rprint(plugin_table)

print("\nTo reconfigure, call `linode-cli configure`")
print(
Expand Down
14 changes: 10 additions & 4 deletions linodecli/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
from enum import Enum
from sys import stdout

from terminaltables import SingleTable
from rich import box
from rich import print as rprint
from rich.table import Table
from rich.text import Text


class OutputMode(Enum):
Expand Down Expand Up @@ -134,15 +137,18 @@ def _table_output(
),
)

tab = SingleTable(content)
tab = Table(*content[0], header_style="", box=box.SQUARE)
for row in content[1:]:
row = [Text.from_ansi(item) for item in row]
tab.add_row(*row)

if title is not None:
tab.title = title

if not self.headers:
tab.inner_heading_row_border = False
tab.show_header = False

print(tab.table, file=to)
rprint(tab, file=to)

def _delimited_output(self, header, data, columns, to):
"""
Expand Down
12 changes: 8 additions & 4 deletions linodecli/plugins/firewall-editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
from ipaddress import IPv4Address, ip_address
from typing import Callable

from terminaltables import PorcelainTable
from rich import box
from rich import print as rprint
from rich.table import Table

from linodecli.plugins import inherit_plugin_args

Expand Down Expand Up @@ -272,9 +274,11 @@ def print_rules_table(rules):
]
)

tab = PorcelainTable([header] + rows)
tab.inner_heading_row_border = True
print(tab.table)
tab = Table(*header, box=box.ASCII, show_edge=False)
for row in rows:
row = [str(r) for r in row]
tab.add_row(*row)
rprint(tab)


def draw_rules(rules):
Expand Down
29 changes: 20 additions & 9 deletions linodecli/plugins/obj/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
from pathlib import Path
from typing import List

from terminaltables import SingleTable
from rich import print as rprint
from rich.table import Table

from linodecli.cli import CLI
from linodecli.configuration import _do_get_request
Expand Down Expand Up @@ -121,20 +122,29 @@ def list_objects_or_buckets(
if key == prefix:
continue

data.append((obj.get("LastModified"), obj.get("Size"), key))
data.append(
(
_convert_datetime(obj.get("LastModified")),
obj.get("Size"),
key,
)
)

if data:
tab = _borderless_table(data)
print(tab.table)
rprint(tab)

sys.exit(0)
else:
# list buckets
buckets = client.list_buckets().get("Buckets", [])
data = [[b.get("CreationDate"), b.get("Name")] for b in buckets]
data = [
[_convert_datetime(b.get("CreationDate")), b.get("Name")]
for b in buckets
]

tab = _borderless_table(data)
print(tab.table)
rprint(tab)

sys.exit(0)

Expand Down Expand Up @@ -388,7 +398,7 @@ def show_usage(get_client, args):
tab = _borderless_table(
[[_pad_to(total, length=7), f"{obj_count} objects", b]]
)
print(tab.table)
rprint(tab)

if len(bucket_names) > 1:
print("--------")
Expand Down Expand Up @@ -486,9 +496,10 @@ def print_help(parser: ArgumentParser):
for name, func in sorted(COMMAND_MAP.items())
]

tab = SingleTable(command_help_map)
tab.inner_heading_row_border = False
print(tab.table)
tab = Table(show_header=False)
for row in command_help_map:
tab.add_row(*row)
rprint(tab)
print()
print(
"Additionally, you can regenerate your Object Storage keys using the "
Expand Down
15 changes: 7 additions & 8 deletions linodecli/plugins/obj/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from argparse import ArgumentTypeError
from datetime import datetime

from terminaltables import SingleTable
from rich.table import Table
from rich.text import Text

from linodecli.plugins.obj.config import DATE_FORMAT

Expand Down Expand Up @@ -120,13 +121,11 @@ def _denominate(total):
# helper functions for output
def _borderless_table(data):
"""
Returns a terminaltables.SingleTable object with no borders and correct padding
Returns a rich.Table object with no borders and correct padding
"""
tab = SingleTable(data)
tab.inner_heading_row_border = False
tab.inner_column_border = False
tab.outer_border = False
tab.padding_left = 0
tab.padding_right = 2
tab = Table.grid(padding=(0, 2, 0, 2))
for row in data:
row = [Text.from_ansi(str(item)) for item in row]
tab.add_row(*row)

return tab
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pylint==2.17.2
pylint==2.17.3
pytest==7.3.1
black>=23.1.0
isort>=5.12.0
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
terminaltables
requests
PyYAML
packaging
packaging
rich
3 changes: 1 addition & 2 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import configparser
import sys

import pytest

Expand Down Expand Up @@ -41,7 +40,7 @@ def mock_cli(
# We need this to suppress warnings for operations that don't
# have access to the cli.suppress_warnings attribute.
# e.g. operation defaults
sys.argv.append("--suppress-warnings")
# sys.argv.append("--suppress-warnings")

return result

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_api_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import io
import json
from types import SimpleNamespace
from unittest.mock import Mock, patch

import requests
from mock import Mock, patch

from linodecli import api_request

Expand Down
Loading

0 comments on commit 0b915fb

Please sign in to comment.