Skip to content

Commit 2ef7407

Browse files
authored
Fix auth output json (#229)
* Fix for auth json output * Bump version: 1.8.7 → 1.8.8
1 parent 9511491 commit 2ef7407

File tree

5 files changed

+31
-13
lines changed

5 files changed

+31
-13
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 1.8.7
2+
current_version = 1.8.8
33
commit = True
44
tag = True
55
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<revision>\d+)

.envrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ if [ ! -f .env ]; then
6161
fi
6262
dotenv
6363

64+
# --- Install pre-commit hooks (same as before)
65+
pre-commit install
66+
67+
# --- Python / Locale (same as before)
6468
# --- Install pre-commit hooks
6569
pre-commit install
6670

@@ -70,5 +74,6 @@ export LC_ALL='en_US.UTF-8'
7074
export LANG='en_US.UTF-8'
7175
export LANGUAGE='en_US.UTF-8'
7276

77+
# --- PATH (same as before)
7378
# --- PATH
7479
path_add PATH "$(expand_path bin)"

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
## [1.8.8] - 2025-11-05
11+
12+
### Fixed
13+
14+
- `--json` flag for the auth command now outputs json only.
15+
1016
### Added
1117

1218
- Added Python 3.14 support

cloudsmith_cli/cli/commands/tokens.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from .main import main
99

1010

11-
def handle_duplicate_token_error(exc, ctx, opts, save_config, force):
11+
def handle_duplicate_token_error(exc, ctx, opts, save_config, force, json):
1212
"""
1313
Handle the case where user already has a token.
1414
@@ -26,7 +26,7 @@ def handle_duplicate_token_error(exc, ctx, opts, save_config, force):
2626
):
2727
return None
2828
return refresh_existing_token_interactive(
29-
ctx, opts, save_config=save_config, force=force
29+
ctx, opts, save_config=save_config, force=force, json=json
3030
)
3131
raise exc
3232

@@ -137,7 +137,7 @@ def print_tokens(tokens):
137137

138138

139139
def refresh_existing_token_interactive(
140-
ctx, opts, token_slug=None, save_config=False, force=False
140+
ctx, opts, token_slug=None, save_config=False, force=False, json=False
141141
):
142142
"""Refresh an existing API token with interactive token selection, or create new if none exist."""
143143
context_msg = "Failed to refresh the token!"
@@ -159,8 +159,9 @@ def refresh_existing_token_interactive(
159159
click.echo("No existing tokens found. Creating a new token instead...")
160160
return _create(ctx, opts, save_config=save_config, force=force)
161161

162-
click.echo("Current tokens:")
163-
print_tokens(api_tokens)
162+
if not json:
163+
click.echo("Current tokens:")
164+
print_tokens(api_tokens)
164165

165166
if not force:
166167
token_slug = click.prompt(
@@ -169,9 +170,11 @@ def refresh_existing_token_interactive(
169170
else:
170171
# Use the first available slug_perm when force is enabled
171172
token_slug = api_tokens[0].slug_perm
172-
click.echo(f"Using token {token_slug} (first available)")
173+
if not json:
174+
click.echo(f"Using token {token_slug} (first available)")
173175

174-
click.echo(f"Refreshing token {token_slug}... ", nl=False)
176+
if not json:
177+
click.echo(f"Refreshing token {token_slug}... ", nl=False)
175178
try:
176179
with handle_api_exceptions(ctx, opts=opts, context_msg=context_msg):
177180
with maybe_spinner(opts):
@@ -186,8 +189,9 @@ def refresh_existing_token_interactive(
186189
if maybe_print_as_json(opts, new_token):
187190
return
188191

189-
click.secho("OK", fg="green")
190-
click.echo(f"New token value: {click.style(new_token.key, fg='magenta')}")
192+
if not json:
193+
click.secho("OK", fg="green")
194+
click.echo(f"New token value: {click.style(new_token.key, fg='magenta')}")
191195

192196
return new_token
193197
except exceptions.ApiException as exc:
@@ -210,7 +214,10 @@ def _create(ctx, opts, save_config=False, force=False, json=False):
210214
return
211215
if maybe_print_as_json(opts, new_token):
212216
return
213-
click.echo(f"New token value: {click.style(new_token.key, fg='magenta')}")
217+
if not json:
218+
click.echo(
219+
f"New token value: {click.style(new_token.key, fg='magenta')}"
220+
)
214221
return new_token
215222

216223
return new_token
@@ -223,6 +230,6 @@ def _create(ctx, opts, save_config=False, force=False, json=False):
223230
opts.output = "json"
224231
if exc.status == 400:
225232
new_token = handle_duplicate_token_error(
226-
exc, ctx, opts, save_config=save_config, force=force
233+
exc, ctx, opts, save_config=save_config, force=force, json=json
227234
)
228235
return new_token

cloudsmith_cli/data/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.8.7
1+
1.8.8

0 commit comments

Comments
 (0)