Skip to content

Commit c27afcd

Browse files
committed
Add --quiet option to silence spinners
1 parent e68203d commit c27afcd

File tree

3 files changed

+57
-12
lines changed

3 files changed

+57
-12
lines changed

proxygen_cli/cli/command_instance.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import os
2+
import sys
13
from typing import get_args
24
from urllib import parse
35

@@ -55,8 +57,14 @@ def list(ctx, env):
5557
show_default=True,
5658
help="Do not prompt for confirmation.",
5759
)
60+
@click.option(
61+
"--quiet",
62+
is_flag=True,
63+
show_default=True,
64+
help="Suppress spinner output.",
65+
)
5866
@click.pass_context
59-
def deploy(ctx, env, base_path, spec_file, no_confirm):
67+
def deploy(ctx, env, base_path, spec_file, no_confirm, quiet):
6068
"""
6169
Deploy <SPEC_FILE> to <ENV> under <BASE_PATH>
6270
@@ -86,7 +94,7 @@ def deploy(ctx, env, base_path, spec_file, no_confirm):
8694
if not click.confirm(f"Deploy this spec to {_url}?"): # pragma: no cover
8795
raise click.Abort()
8896

89-
with yaspin() as sp:
97+
with yaspin(stream=open(os.devnull, 'w') if quiet else sys.stdout) as sp:
9098
sp.text = f"Deploying {_url}"
9199
instance = parse.quote(base_path)
92100

@@ -127,8 +135,14 @@ def get(ctx, env, base_path):
127135
show_default=True,
128136
help="Do not prompt for confirmation.",
129137
)
138+
@click.option(
139+
"--quiet",
140+
is_flag=True,
141+
show_default=True,
142+
help="Suppress spinner output.",
143+
)
130144
@click.pass_context
131-
def delete(ctx, env, base_path, no_confirm):
145+
def delete(ctx, env, base_path, no_confirm, quiet):
132146
"""
133147
Delete the instance deployed on <BASE_PATH> in environment <ENV>.
134148
"""
@@ -144,7 +158,7 @@ def delete(ctx, env, base_path, no_confirm):
144158
if not click.confirm(f"Delete the instance at {_url}?"):
145159
raise click.Abort()
146160

147-
with yaspin() as sp:
161+
with yaspin(stream=open(os.devnull, 'w') if quiet else sys.stdout) as sp:
148162
sp.text = f"Deleting {_url}"
149163

150164
try:

proxygen_cli/cli/command_secret.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import os
2+
import sys
13
from typing import get_args
24

35
import click
@@ -119,8 +121,14 @@ def _read_or_fail(secret_file: str, type_label: str) -> str:
119121
@click.option(
120122
"--mtls-key", help="Provide a path to a PEM encoded private key for mutual TLS"
121123
)
124+
@click.option(
125+
"--quiet",
126+
is_flag=True,
127+
show_default=True,
128+
help="Suppress spinner output.",
129+
)
122130
@click.pass_context
123-
def put(ctx, env, secret_name, secret_value, secret_file, apikey, mtls_cert, mtls_key):
131+
def put(ctx, env, secret_name, secret_value, secret_file, apikey, mtls_cert, mtls_key, quiet):
124132
"""
125133
Create or overwrite a secret.
126134
@@ -133,7 +141,7 @@ def put(ctx, env, secret_name, secret_value, secret_file, apikey, mtls_cert, mtl
133141
secret_value, secret_file, apikey, mtls_cert, mtls_key
134142
)
135143

136-
with yaspin() as spinner:
144+
with yaspin(stream=open(os.devnull, 'w') if quiet else sys.stdout) as spinner:
137145
spinner.text = f"Putting secret {secret_name} in {env}"
138146

139147
try:
@@ -183,8 +191,14 @@ def describe(ctx, env, secret_type, secret_name):
183191
show_default=True,
184192
help="Do not prompt for confirmation.",
185193
)
194+
@click.option(
195+
"--quiet",
196+
is_flag=True,
197+
show_default=True,
198+
help="Suppress spinner output.",
199+
)
186200
@click.pass_context
187-
def delete(ctx, env, secret_type, secret_name, no_confirm):
201+
def delete(ctx, env, secret_type, secret_name, no_confirm, quiet):
188202
"""
189203
Delete a secret.
190204
"""
@@ -199,7 +213,7 @@ def delete(ctx, env, secret_type, secret_name, no_confirm):
199213
output.print_json(result)
200214
if not click.confirm(f"Delete secret {secret_name} from {env}?"):
201215
raise click.Abort()
202-
with yaspin() as sp:
216+
with yaspin(stream=open(os.devnull, 'w') if quiet else sys.stdout) as sp:
203217
sp.text = f"Deleting secret {secret_name} from {env}"
204218
try:
205219
result = proxygen_api.delete_secret(api, env, secret_type, secret_name)

proxygen_cli/cli/command_spec.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import os
2+
import sys
13
from typing import get_args
24

35
import click
@@ -13,6 +15,7 @@
1315

1416
HELP_NO_CONFIRM = "Do not prompt for confirmation."
1517
HELP_UAT = "Target the UAT instance of API catalogue."
18+
HELP_QUIET = "Suppress spinner output."
1619

1720
UAT_KWARGS = {
1821
'default': False,
@@ -26,6 +29,12 @@
2629
'help': HELP_NO_CONFIRM,
2730
}
2831

32+
QUIET_KWARGS = {
33+
'is_flag': True,
34+
'show_default': True,
35+
'help': HELP_QUIET,
36+
}
37+
2938

3039
@click.group()
3140
@click.option(
@@ -56,8 +65,12 @@ def spec(ctx, api, uat):
5665
"--uat",
5766
**UAT_KWARGS
5867
)
68+
@click.option(
69+
"--quiet",
70+
**QUIET_KWARGS
71+
)
5972
@click.pass_context
60-
def publish(ctx, spec_file, no_confirm, uat):
73+
def publish(ctx, spec_file, no_confirm, uat, quiet):
6174
"""
6275
Publish <SPEC_FILE>.
6376
"""
@@ -70,7 +83,7 @@ def publish(ctx, spec_file, no_confirm, uat):
7083
if not click.confirm(f"Publish this spec for {api}?"):
7184
raise click.Abort()
7285

73-
with yaspin() as sp:
86+
with yaspin(stream=open(os.devnull, 'w') if quiet else sys.stdout) as sp:
7487
sp.text = f"Publishing spec {api}"
7588

7689
try:
@@ -124,8 +137,12 @@ def get(ctx, uat):
124137
"--uat",
125138
**UAT_KWARGS
126139
)
140+
@click.option(
141+
"--quiet",
142+
**QUIET_KWARGS
143+
)
127144
@click.pass_context
128-
def delete(ctx, no_confirm, uat):
145+
def delete(ctx, no_confirm, uat, quiet):
129146
"""
130147
Delete the published spec.
131148
"""
@@ -138,7 +155,7 @@ def delete(ctx, no_confirm, uat):
138155
if not click.confirm(f"Delete the spec at {api}?"):
139156
raise click.Abort()
140157

141-
with yaspin() as sp:
158+
with yaspin(stream=open(os.devnull, 'w') if quiet else sys.stdout) as sp:
142159
sp.text = f"Deleting spec {api}"
143160

144161
try:

0 commit comments

Comments
 (0)