-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add kubectl-ng config current-context (#375)
- Loading branch information
1 parent
41fac23
commit 450c89b
Showing
3 changed files
with
44 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# SPDX-FileCopyrightText: Copyright (c) 2024, Kr8s Developers (See LICENSE for list) | ||
# SPDX-License-Identifier: BSD 3-Clause License | ||
import typer | ||
|
||
import kr8s | ||
|
||
config = typer.Typer( | ||
no_args_is_help=True, | ||
name="config", | ||
help="Modify kubeconfig files.", | ||
) | ||
|
||
|
||
@config.command(name="current-context", help="Display the current-context") | ||
def config_current_context(): | ||
"""Display the current context.""" | ||
try: | ||
typer.echo(kr8s.api().auth.kubeconfig.current_context) | ||
except KeyError: | ||
typer.echo("error: current-context is not set") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# SPDX-FileCopyrightText: Copyright (c) 2024, Kr8s Developers (See LICENSE for list) | ||
# SPDX-License-Identifier: BSD 3-Clause License | ||
from kubectl_ng.cli import app | ||
from typer.testing import CliRunner | ||
|
||
import kr8s | ||
|
||
runner = CliRunner() | ||
|
||
|
||
def test_create_and_delete(): | ||
current_context = kr8s.api().auth.kubeconfig.current_context | ||
result = runner.invoke(app, ["config", "current-context"]) | ||
assert result.exit_code == 0 | ||
assert current_context in result.stdout |