Skip to content

Commit b74d067

Browse files
authored
feat(CLI): allow specifying environment variables by name only (#234)
* feat(CLI): allow specifying environment variables by name only * docs(CLI): update docs for `cluster vars new` and `cluster vars update`
1 parent 3a719c5 commit b74d067

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

silverback/_cli.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,16 @@ def vars():
926926

927927
def parse_envvars(ctx, name, value: list[str]) -> dict[str, str]:
928928
def parse_envar(item: str):
929-
if not ("=" in item and len(item.split("=")) == 2):
929+
930+
if "=" not in item:
931+
if not (envvar := os.environ.get(item)):
932+
raise click.UsageError(
933+
f"Environment variable '{item}' has no value in your environment"
934+
)
935+
936+
return item, envvar
937+
938+
elif len(item.split("=")) != 2:
930939
raise click.UsageError(f"Value '{item}' must be in form `NAME=VAL`")
931940

932941
return item.split("=")
@@ -941,9 +950,9 @@ def parse_envar(item: str):
941950
"variables",
942951
multiple=True,
943952
type=str,
944-
metavar="NAME=VAL",
953+
metavar="NAME[=VAL]",
945954
callback=parse_envvars,
946-
help="Environment variable key and value to add (Multiple allowed)",
955+
help="Environment variable name or key and value to add (Multiple allowed)",
947956
)
948957
@click.argument("name")
949958
@cluster_client()
@@ -988,9 +997,9 @@ def vargroup_info(cluster: "ClusterClient", name: str):
988997
"updated_vars",
989998
multiple=True,
990999
type=str,
991-
metavar="NAME=VAL",
1000+
metavar="NAME[=VAL]",
9921001
callback=parse_envvars,
993-
help="Environment variable key and value to add/update (Multiple allowed)",
1002+
help="Environment variable name or key and value to add/update (Multiple allowed)",
9941003
)
9951004
@click.option(
9961005
"-d",

0 commit comments

Comments
 (0)