Skip to content

Commit

Permalink
Merge pull request #613 from linode/dev
Browse files Browse the repository at this point in the history
v5.50.0
  • Loading branch information
jriddle-linode authored Jun 3, 2024
2 parents 91167c3 + 8ea0a3d commit 0bca21c
Show file tree
Hide file tree
Showing 40 changed files with 762 additions and 330 deletions.
25 changes: 6 additions & 19 deletions .github/workflows/e2e-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,34 +44,21 @@ jobs:
run: |
timestamp=$(date +'%Y%m%d%H%M')
report_filename="${timestamp}_cli_test_report.xml"
if ! pytest tests/integration --disable-warnings --junitxml="${report_filename}"; then
echo "EXIT_STATUS=1" >> $GITHUB_ENV
fi
make testint TEST_ARGS="--junitxml=${report_filename}"
env:
LINODE_CLI_TOKEN: ${{ secrets.LINODE_TOKEN }}

- name: Add additional information to XML report
- name: Upload test results
if: always()
run: |
filename=$(ls | grep -E '^[0-9]{12}_cli_test_report\.xml$')
filename=$(ls | grep -E '^[0-9]{12}_cli_test_report\.xml$')
python tod_scripts/add_to_xml_test_report.py \
--branch_name "${GITHUB_REF#refs/*/}" \
--gha_run_id "$GITHUB_RUN_ID" \
--gha_run_number "$GITHUB_RUN_NUMBER" \
--xmlfile "${filename}"
- name: Upload test results
run: |
filename=$(ls | grep -E '^[0-9]{12}_cli_test_report\.xml$')
sync
python tod_scripts/test_report_upload_script.py "${filename}"
env:
LINODE_CLI_OBJ_ACCESS_KEY: ${{ secrets.LINODE_CLI_OBJ_ACCESS_KEY }}
LINODE_CLI_OBJ_SECRET_KEY: ${{ secrets.LINODE_CLI_OBJ_SECRET_KEY }}

- name: Test Execution Status Handler
run: |
if [[ "$EXIT_STATUS" != 0 ]]; then
echo "Test execution contains failure(s)"
exit $EXIT_STATUS
else
echo "Tests passed!"
fi
LINODE_CLI_OBJ_SECRET_KEY: ${{ secrets.LINODE_CLI_OBJ_SECRET_KEY }}
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#
MODULE :=
TEST_CASE_COMMAND :=
TEST_ARGS :=

ifdef TEST_CASE
TEST_CASE_COMMAND = -k $(TEST_CASE)
Expand Down Expand Up @@ -71,7 +72,7 @@ testunit:

.PHONY: testint
testint:
pytest tests/integration/${MODULE} ${TEST_CASE_COMMAND}
pytest tests/integration/${MODULE} ${TEST_CASE_COMMAND} ${TEST_ARGS}

.PHONY: testall
testall:
Expand Down
73 changes: 31 additions & 42 deletions linodecli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from sys import argv

from rich import print as rprint
from rich.table import Table
from rich.table import Column, Table

from linodecli import plugins

Expand All @@ -23,9 +23,16 @@
from .cli import CLI
from .completion import get_completions
from .configuration import ENV_TOKEN_NAME
from .help_pages import print_help_action, print_help_default
from .help_pages import (
HELP_TOPICS,
print_help_action,
print_help_commands,
print_help_default,
print_help_env_vars,
print_help_plugins,
)
from .helpers import handle_url_overrides
from .output import OutputMode
from .output.output_handler import OutputMode
from .version import __version__

VERSION = __version__
Expand Down Expand Up @@ -57,54 +64,19 @@ def main(): # pylint: disable=too-many-branches,too-many-statements
)
parsed, args = register_args(parser).parse_known_args()

# output/formatting settings
if parsed.text:
cli.output_handler.mode = OutputMode.delimited
elif parsed.json:
cli.output_handler.mode = OutputMode.json
cli.output_handler.columns = "*"
elif parsed.markdown:
cli.output_handler.mode = OutputMode.markdown
elif parsed.ascii_table:
cli.output_handler.mode = OutputMode.ascii_table

if parsed.delimiter:
cli.output_handler.delimiter = parsed.delimiter
if parsed.pretty:
cli.output_handler.mode = OutputMode.json
cli.output_handler.pretty_json = True
cli.output_handler.columns = "*"
if parsed.no_headers:
cli.output_handler.headers = False
cli.output_handler.configure(parsed, cli.suppress_warnings)

if parsed.all_rows:
cli.pagination = False
elif parsed.format:
cli.output_handler.columns = parsed.format

cli.defaults = not parsed.no_defaults
cli.retry_count = 0
cli.no_retry = parsed.no_retry
cli.suppress_warnings = parsed.suppress_warnings

if parsed.all_columns or parsed.all:
if parsed.all and not cli.suppress_warnings:
print(
"WARNING: '--all' is a deprecated flag, "
"and will be removed in a future version. "
"Please consider use '--all-columns' instead."
)
cli.output_handler.columns = "*"

cli.page = parsed.page
cli.page_size = parsed.page_size
cli.debug_request = parsed.debug

cli.output_handler.suppress_warnings = parsed.suppress_warnings
cli.output_handler.disable_truncation = parsed.no_truncation
cli.output_handler.column_width = parsed.column_width
cli.output_handler.single_table = parsed.single_table
cli.output_handler.tables = parsed.table

if parsed.as_user and not skip_config:
cli.config.set_user(parsed.as_user)

Expand Down Expand Up @@ -154,7 +126,19 @@ def main(): # pylint: disable=too-many-branches,too-many-statements
# handle a help for the CLI
if parsed.command is None or (parsed.command is None and parsed.help):
parser.print_help()
print_help_default(cli.ops, cli.config)
print_help_default()
sys.exit(0)

if parsed.command == "env-vars":
print_help_env_vars()
sys.exit(0)

if parsed.command == "commands":
print_help_commands(cli.ops)
sys.exit(0)

if parsed.command == "plugins":
print_help_plugins(cli.config)
sys.exit(0)

# configure
Expand Down Expand Up @@ -224,6 +208,7 @@ def main(): # pylint: disable=too-many-branches,too-many-statements
if (
parsed.command not in cli.ops
and parsed.command not in plugins.available(cli.config)
and parsed.command not in HELP_TOPICS
):
print(f"Unrecognized command {parsed.command}")
sys.exit(1)
Expand All @@ -243,9 +228,13 @@ def main(): # pylint: disable=too-many-branches,too-many-statements
for action, op in cli.ops[parsed.command].items()
]

table = Table("action", "summary")
table = Table(
Column(header="action", no_wrap=True),
Column(header="summary", style="cyan"),
)
for row in content:
table.add_row(*row)

rprint(table)
sys.exit(0)

Expand Down
90 changes: 7 additions & 83 deletions linodecli/arg_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@

from linodecli import plugins
from linodecli.helpers import (
pagination_args_shared,
register_args_shared,
register_debug_arg,
register_pagination_args_shared,
)
from linodecli.output.helpers import register_output_args_shared


def register_args(parser):
Expand All @@ -41,106 +42,29 @@ def register_args(parser):
action="store_true",
help="Display information about a command, action, or the CLI overall.",
)
parser.add_argument(
"--text",
action="store_true",
help="Display text output with a delimiter (defaults to tabs).",
)
parser.add_argument(
"--delimiter",
metavar="DELIMITER",
type=str,
help="The delimiter when displaying raw output.",
)
parser.add_argument(
"--json", action="store_true", help="Display output as JSON."
)
parser.add_argument(
"--markdown",
action="store_true",
help="Display output in Markdown format.",
)
parser.add_argument(
"--ascii-table",
action="store_true",
help="Display output in an ASCII table.",
)
parser.add_argument(
"--pretty",
action="store_true",
help="If set, pretty-print JSON output.",
)
parser.add_argument(
"--no-headers",
action="store_true",
help="If set, does not display headers in output.",
)
parser.add_argument(
"--all",
action="store_true",
help=(
"Deprecated flag. An alias of '--all-columns', "
"scheduled to be removed in a future version."
),
)
parser.add_argument(
"--all-columns",
action="store_true",
help=(
"If set, displays all possible columns instead of "
"the default columns. This may not work well on some terminals."
),
)
parser.add_argument(
"--format",
metavar="FORMAT",
type=str,
help="The columns to display in output. Provide a comma-"
"separated list of column names.",
)

parser.add_argument(
"--no-defaults",
action="store_true",
help="Suppress default values for arguments. Default values "
"are configured on initial setup or with linode-cli configure",
)
parser.add_argument(
"--no-truncation",
action="store_true",
default=False,
help="Prevent the truncation of long values in command outputs.",
)

parser.add_argument(
"--no-retry",
action="store_true",
help="Skip retrying on common errors like timeouts.",
)
parser.add_argument(
"--single-table",
action="store_true",
help="Disable printing multiple tables for complex API responses.",
)
parser.add_argument(
"--table",
type=str,
action="append",
help="The specific table(s) to print in output of a command.",
)
parser.add_argument(
"--column-width",
type=int,
default=None,
help="Sets the maximum width of each column in outputted tables. "
"By default, columns are dynamically sized to fit the terminal.",
)

parser.add_argument(
"--version",
"-v",
action="store_true",
help="Prints version information and exits.",
)

pagination_args_shared(parser)
register_output_args_shared(parser)
register_pagination_args_shared(parser)
register_args_shared(parser)
register_debug_arg(parser)

Expand Down
64 changes: 0 additions & 64 deletions linodecli/baked/colors.py

This file was deleted.

2 changes: 1 addition & 1 deletion linodecli/baked/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from linodecli.baked.request import OpenAPIFilteringRequest, OpenAPIRequest
from linodecli.baked.response import OpenAPIResponse
from linodecli.output import OutputHandler
from linodecli.output.output_handler import OutputHandler
from linodecli.overrides import OUTPUT_OVERRIDES


Expand Down
Loading

0 comments on commit 0bca21c

Please sign in to comment.