-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
kubectl-ng config use/rename context (#379)
- Loading branch information
1 parent
be11745
commit a7a5c3c
Showing
4 changed files
with
103 additions
and
29 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
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,28 @@ | ||
# SPDX-FileCopyrightText: Copyright (c) 2024, Kr8s Developers (See LICENSE for list) | ||
# SPDX-License-Identifier: BSD 3-Clause License | ||
|
||
import asyncio | ||
from functools import wraps | ||
|
||
import typer | ||
|
||
|
||
def _typer_async(f): | ||
@wraps(f) | ||
def wrapper(*args, **kwargs): | ||
return asyncio.run(f(*args, **kwargs)) | ||
|
||
return wrapper | ||
|
||
|
||
def register(app, func, alias=None): | ||
if asyncio.iscoroutinefunction(func): | ||
func = _typer_async(func) | ||
if isinstance(func, typer.Typer): | ||
assert alias, "Typer subcommand must have an alias." | ||
app.add_typer(func, name=alias) | ||
else: | ||
if alias is not None: | ||
app.command(alias)(func) | ||
else: | ||
app.command()(func) |
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