cloudsmith-cli 1.10.2__py2.py3-none-any.whl → 1.10.4__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. cloudsmith_cli/cli/command.py +66 -0
  2. cloudsmith_cli/cli/commands/auth.py +25 -12
  3. cloudsmith_cli/cli/commands/check.py +18 -4
  4. cloudsmith_cli/cli/commands/copy.py +8 -2
  5. cloudsmith_cli/cli/commands/delete.py +9 -3
  6. cloudsmith_cli/cli/commands/dependencies.py +1 -1
  7. cloudsmith_cli/cli/commands/download.py +89 -8
  8. cloudsmith_cli/cli/commands/entitlements.py +11 -7
  9. cloudsmith_cli/cli/commands/list_.py +2 -2
  10. cloudsmith_cli/cli/commands/login.py +21 -13
  11. cloudsmith_cli/cli/commands/metrics/entitlements.py +2 -2
  12. cloudsmith_cli/cli/commands/metrics/packages.py +1 -1
  13. cloudsmith_cli/cli/commands/move.py +10 -3
  14. cloudsmith_cli/cli/commands/policy/deny.py +8 -6
  15. cloudsmith_cli/cli/commands/policy/license.py +5 -3
  16. cloudsmith_cli/cli/commands/policy/vulnerability.py +6 -3
  17. cloudsmith_cli/cli/commands/push.py +146 -64
  18. cloudsmith_cli/cli/commands/quarantine.py +7 -4
  19. cloudsmith_cli/cli/commands/quota/history.py +1 -1
  20. cloudsmith_cli/cli/commands/quota/quota.py +1 -1
  21. cloudsmith_cli/cli/commands/repos.py +5 -3
  22. cloudsmith_cli/cli/commands/resync.py +7 -2
  23. cloudsmith_cli/cli/commands/status.py +21 -3
  24. cloudsmith_cli/cli/commands/tags.py +20 -5
  25. cloudsmith_cli/cli/commands/tokens.py +37 -25
  26. cloudsmith_cli/cli/commands/upstream.py +2 -3
  27. cloudsmith_cli/cli/commands/whoami.py +4 -5
  28. cloudsmith_cli/cli/exceptions.py +86 -49
  29. cloudsmith_cli/cli/utils.py +17 -2
  30. cloudsmith_cli/cli/webserver.py +1 -1
  31. cloudsmith_cli/data/VERSION +1 -1
  32. {cloudsmith_cli-1.10.2.dist-info → cloudsmith_cli-1.10.4.dist-info}/METADATA +1 -1
  33. {cloudsmith_cli-1.10.2.dist-info → cloudsmith_cli-1.10.4.dist-info}/RECORD +37 -37
  34. {cloudsmith_cli-1.10.2.dist-info → cloudsmith_cli-1.10.4.dist-info}/WHEEL +0 -0
  35. {cloudsmith_cli-1.10.2.dist-info → cloudsmith_cli-1.10.4.dist-info}/entry_points.txt +0 -0
  36. {cloudsmith_cli-1.10.2.dist-info → cloudsmith_cli-1.10.4.dist-info}/licenses/LICENSE +0 -0
  37. {cloudsmith_cli-1.10.2.dist-info → cloudsmith_cli-1.10.4.dist-info}/top_level.txt +0 -0
@@ -63,7 +63,7 @@ def deny_policy(*args, **kwargs):
63
63
  @click.pass_context
64
64
  def list_deny_policies(ctx, opts, owner, page, page_size, page_all):
65
65
  """List deny policies for an organization."""
66
- use_stderr = opts.output != "pretty"
66
+ use_stderr = utils.should_use_stderr(opts)
67
67
  click.echo("Getting deny policies ... ", nl=False, err=use_stderr)
68
68
 
69
69
  context_msg = "Failed to get deny policies!"
@@ -104,7 +104,7 @@ def create_deny_policy(ctx, opts, owner, policy_config_file):
104
104
  """Create a deny policy for an organization."""
105
105
  import json
106
106
 
107
- use_stderr = opts.output != "pretty"
107
+ use_stderr = utils.should_use_stderr(opts)
108
108
  policy_config = json.load(policy_config_file)
109
109
 
110
110
  policy_name = policy_config.get("name")
@@ -146,7 +146,7 @@ def create_deny_policy(ctx, opts, owner, policy_config_file):
146
146
  @click.pass_context
147
147
  def get_deny_policy(ctx, opts, owner, identifier):
148
148
  """Get a deny policy for an organization."""
149
- use_stderr = opts.output != "pretty"
149
+ use_stderr = utils.should_use_stderr(opts)
150
150
  click.echo("Getting deny policy ... ", nl=False, err=use_stderr)
151
151
 
152
152
  context_msg = "Failed to get deny policy!"
@@ -175,7 +175,7 @@ def update_deny_policy(ctx, opts, owner, identifier, policy_config_file):
175
175
  """Update a deny policy for an organization."""
176
176
  import json
177
177
 
178
- use_stderr = opts.output != "pretty"
178
+ use_stderr = utils.should_use_stderr(opts)
179
179
  policy_config = json.load(policy_config_file)
180
180
 
181
181
  click.secho(
@@ -230,12 +230,14 @@ def delete_deny_policy(ctx, opts, owner, identifier, yes):
230
230
  % delete_args
231
231
  )
232
232
 
233
- if not utils.confirm_operation(prompt, assume_yes=yes):
233
+ use_stderr = utils.should_use_stderr(opts)
234
+ if not utils.confirm_operation(prompt, assume_yes=yes, err=use_stderr):
234
235
  return
235
236
 
236
237
  click.secho(
237
238
  "Deleting %(identifier)s from the %(namespace)s namespace ... " % delete_args,
238
239
  nl=False,
240
+ err=use_stderr,
239
241
  )
240
242
 
241
243
  context_msg = "Failed to delete the deny policy!"
@@ -243,4 +245,4 @@ def delete_deny_policy(ctx, opts, owner, identifier, yes):
243
245
  with maybe_spinner(opts):
244
246
  orgs.delete_deny_policy(owner=owner, slug_perm=identifier)
245
247
 
246
- click.secho("OK", fg="green")
248
+ click.secho("OK", fg="green", err=use_stderr)
@@ -100,7 +100,7 @@ def ls(ctx, opts, owner, page, page_size, page_all):
100
100
  owner = owner[0]
101
101
 
102
102
  # Use stderr for messages if the output is something else (e.g. # JSON)
103
- use_stderr = opts.output != "pretty"
103
+ use_stderr = utils.should_use_stderr(opts)
104
104
 
105
105
  click.echo("Getting license policies ... ", nl=False, err=use_stderr)
106
106
 
@@ -316,13 +316,15 @@ def delete(ctx, opts, owner, identifier, yes):
316
316
  "delete the %(slug_perm)s license policy from the %(namespace)s namespace"
317
317
  % delete_args
318
318
  )
319
+ use_stderr = utils.should_use_stderr(opts)
319
320
 
320
- if not utils.confirm_operation(prompt, assume_yes=yes):
321
+ if not utils.confirm_operation(prompt, assume_yes=yes, err=use_stderr):
321
322
  return
322
323
 
323
324
  click.secho(
324
325
  "Deleting %(slug_perm)s from the %(namespace)s namespace ... " % delete_args,
325
326
  nl=False,
327
+ err=use_stderr,
326
328
  )
327
329
 
328
330
  context_msg = "Failed to delete the license policy!"
@@ -330,4 +332,4 @@ def delete(ctx, opts, owner, identifier, yes):
330
332
  with maybe_spinner(opts):
331
333
  api.delete_license_policy(owner=owner, slug_perm=identifier)
332
334
 
333
- click.secho("OK", fg="green")
335
+ click.secho("OK", fg="green", err=use_stderr)
@@ -90,7 +90,7 @@ def ls(ctx, opts, owner, page, page_size, page_all):
90
90
  owner = owner[0]
91
91
 
92
92
  # Use stderr for messages if the output is something else (e.g. # JSON)
93
- use_stderr = opts.output != "pretty"
93
+ use_stderr = utils.should_use_stderr(opts)
94
94
 
95
95
  click.echo("Getting vulnerability policies ... ", nl=False, err=use_stderr)
96
96
 
@@ -303,12 +303,15 @@ def delete(ctx, opts, owner, identifier, yes):
303
303
  % delete_args
304
304
  )
305
305
 
306
- if not utils.confirm_operation(prompt, assume_yes=yes):
306
+ use_stderr = utils.should_use_stderr(opts)
307
+
308
+ if not utils.confirm_operation(prompt, assume_yes=yes, err=use_stderr):
307
309
  return
308
310
 
309
311
  click.secho(
310
312
  "Deleting %(slug_perm)s from the %(namespace)s namespace ... " % delete_args,
311
313
  nl=False,
314
+ err=use_stderr,
312
315
  )
313
316
 
314
317
  context_msg = "Failed to delete the vulnerability policy!"
@@ -316,4 +319,4 @@ def delete(ctx, opts, owner, identifier, yes):
316
319
  with maybe_spinner(opts):
317
320
  api.delete_vulnerability_policy(owner=owner, slug_perm=identifier)
318
321
 
319
- click.secho("OK", fg="green")
322
+ click.secho("OK", fg="green", err=use_stderr)
@@ -7,7 +7,7 @@ from datetime import datetime
7
7
 
8
8
  import click
9
9
 
10
- from ...core import utils
10
+ from ...core import utils as core_utils
11
11
  from ...core.api.exceptions import ApiException
12
12
  from ...core.api.files import (
13
13
  CHUNK_SIZE,
@@ -22,7 +22,7 @@ from ...core.api.packages import (
22
22
  get_package_status,
23
23
  validate_create_package as api_validate_create_package,
24
24
  )
25
- from .. import command, decorators, validators
25
+ from .. import command, decorators, utils, validators
26
26
  from ..exceptions import handle_api_exceptions
27
27
  from ..types import ExpandPath
28
28
  from ..utils import maybe_spinner
@@ -34,10 +34,13 @@ def validate_upload_file(ctx, opts, owner, repo, filepath, skip_errors):
34
34
  filename = click.format_filename(filepath)
35
35
  basename = os.path.basename(filename)
36
36
 
37
+ use_stderr = utils.should_use_stderr(opts)
38
+
37
39
  click.echo(
38
40
  "Checking %(filename)s file upload parameters ... "
39
41
  % {"filename": click.style(basename, bold=True)},
40
42
  nl=False,
43
+ err=use_stderr,
41
44
  )
42
45
 
43
46
  context_msg = "Failed to validate upload parameters!"
@@ -49,7 +52,7 @@ def validate_upload_file(ctx, opts, owner, repo, filepath, skip_errors):
49
52
  owner=owner, repo=repo, filepath=filename
50
53
  )
51
54
 
52
- click.secho("OK", fg="green")
55
+ click.secho("OK", fg="green", err=use_stderr)
53
56
 
54
57
  return md5_checksum
55
58
 
@@ -59,14 +62,17 @@ def upload_file(ctx, opts, owner, repo, filepath, skip_errors, md5_checksum):
59
62
  filename = click.format_filename(filepath)
60
63
  basename = os.path.basename(filename)
61
64
 
62
- filesize = utils.get_file_size(filepath=filename)
65
+ filesize = core_utils.get_file_size(filepath=filename)
63
66
  projected_chunks = math.floor(filesize / CHUNK_SIZE) + 1
64
67
  is_multi_part_upload = projected_chunks > 1
65
68
 
69
+ use_stderr = utils.should_use_stderr(opts)
70
+
66
71
  click.echo(
67
72
  "Requesting file upload for %(filename)s ... "
68
73
  % {"filename": click.style(basename, bold=True)},
69
74
  nl=False,
75
+ err=use_stderr,
70
76
  )
71
77
 
72
78
  context_msg = "Failed to request file upload!"
@@ -82,51 +88,69 @@ def upload_file(ctx, opts, owner, repo, filepath, skip_errors, md5_checksum):
82
88
  is_multi_part_upload=is_multi_part_upload,
83
89
  )
84
90
 
85
- click.secho("OK", fg="green")
91
+ click.secho("OK", fg="green", err=use_stderr)
86
92
 
87
93
  context_msg = "Failed to upload file!"
88
94
  with handle_api_exceptions(ctx, opts=opts, context_msg=context_msg):
89
95
  label = f"Uploading {click.style(basename, bold=True)}:"
90
96
 
91
97
  if not is_multi_part_upload:
92
- # We can upload the whole file in one go.
93
- with click.progressbar(
94
- length=filesize,
95
- label=label,
96
- fill_char=click.style("#", fg="green"),
97
- empty_char=click.style("-", fg="red"),
98
- ) as pb:
99
-
100
- def progress_callback(monitor):
101
- pb.update(monitor.bytes_read)
102
-
98
+ if use_stderr:
103
99
  api_upload_file(
104
100
  upload_url=upload_url,
105
101
  upload_fields=upload_fields,
106
102
  filepath=filename,
107
- callback=progress_callback,
108
103
  )
104
+ else:
105
+ # We can upload the whole file in one go.
106
+ with click.progressbar(
107
+ length=filesize,
108
+ label=label,
109
+ fill_char=click.style("#", fg="green"),
110
+ empty_char=click.style("-", fg="red"),
111
+ ) as pb:
112
+
113
+ def progress_callback(monitor):
114
+ pb.update(monitor.bytes_read)
115
+
116
+ api_upload_file(
117
+ upload_url=upload_url,
118
+ upload_fields=upload_fields,
119
+ filepath=filename,
120
+ callback=progress_callback,
121
+ )
109
122
  else:
110
- # The file is sufficiently large that we need to upload in chunks.
111
- with click.progressbar(
112
- length=projected_chunks,
113
- label=label,
114
- fill_char=click.style("#", fg="green"),
115
- empty_char=click.style("-", fg="red"),
116
- ) as pb:
117
-
118
- def progress_callback():
119
- pb.update(1)
120
-
123
+ if use_stderr:
121
124
  multi_part_upload_file(
122
125
  opts=opts,
123
126
  upload_url=upload_url,
124
127
  owner=owner,
125
128
  repo=repo,
126
129
  filepath=filename,
127
- callback=progress_callback,
128
130
  upload_id=identifier,
131
+ callback=lambda: None,
129
132
  )
133
+ else:
134
+ # The file is sufficiently large that we need to upload in chunks.
135
+ with click.progressbar(
136
+ length=projected_chunks,
137
+ label=label,
138
+ fill_char=click.style("#", fg="green"),
139
+ empty_char=click.style("-", fg="red"),
140
+ ) as pb:
141
+
142
+ def progress_callback():
143
+ pb.update(1)
144
+
145
+ multi_part_upload_file(
146
+ opts=opts,
147
+ upload_url=upload_url,
148
+ owner=owner,
149
+ repo=repo,
150
+ filepath=filename,
151
+ callback=progress_callback,
152
+ upload_id=identifier,
153
+ )
130
154
 
131
155
  return identifier
132
156
 
@@ -135,10 +159,13 @@ def validate_create_package(
135
159
  ctx, opts, owner, repo, package_type, skip_errors, **kwargs
136
160
  ):
137
161
  """Check new package parameters via the API."""
162
+ use_stderr = utils.should_use_stderr(opts)
163
+
138
164
  click.echo(
139
165
  "Checking %(package_type)s package upload parameters ... "
140
166
  % {"package_type": click.style(package_type, bold=True)},
141
167
  nl=False,
168
+ err=use_stderr,
142
169
  )
143
170
 
144
171
  context_msg = "Failed to validate upload parameters!"
@@ -150,16 +177,19 @@ def validate_create_package(
150
177
  package_format=package_type, owner=owner, repo=repo, **kwargs
151
178
  )
152
179
 
153
- click.secho("OK", fg="green")
180
+ click.secho("OK", fg="green", err=use_stderr)
154
181
  return True
155
182
 
156
183
 
157
184
  def create_package(ctx, opts, owner, repo, package_type, skip_errors, **kwargs):
158
185
  """Create a new package via the API."""
186
+ use_stderr = utils.should_use_stderr(opts)
187
+
159
188
  click.echo(
160
189
  "Creating a new %(package_type)s package ... "
161
190
  % {"package_type": click.style(package_type, bold=True)},
162
191
  nl=False,
192
+ err=use_stderr,
163
193
  )
164
194
 
165
195
  context_msg = "Failed to create package!"
@@ -171,7 +201,7 @@ def create_package(ctx, opts, owner, repo, package_type, skip_errors, **kwargs):
171
201
  package_format=package_type, owner=owner, repo=repo, **kwargs
172
202
  )
173
203
 
174
- click.secho("OK", fg="green")
204
+ click.secho("OK", fg="green", err=use_stderr)
175
205
 
176
206
  click.echo(
177
207
  "Created: %(owner)s/%(repo)s/%(slug)s (%(slug_perm)s)"
@@ -180,7 +210,8 @@ def create_package(ctx, opts, owner, repo, package_type, skip_errors, **kwargs):
180
210
  "repo": click.style(repo, fg="magenta"),
181
211
  "slug": click.style(slug, fg="green"),
182
212
  "slug_perm": click.style(slug_perm, bold=True),
183
- }
213
+ },
214
+ err=use_stderr,
184
215
  )
185
216
 
186
217
  return slug_perm, slug
@@ -191,8 +222,10 @@ def wait_for_package_sync(
191
222
  ):
192
223
  """Wait for a package to synchronise (or fail)."""
193
224
  # pylint: disable=too-many-locals
225
+ use_stderr = utils.should_use_stderr(opts)
226
+
194
227
  attempts -= 1
195
- click.echo()
228
+ click.echo(err=use_stderr)
196
229
  label = f"Synchronising {click.style(slug, fg='green')}:"
197
230
 
198
231
  status_str = "Waiting"
@@ -218,46 +251,64 @@ def wait_for_package_sync(
218
251
  total_wait_interval = max(1.0, wait_interval)
219
252
  first = True
220
253
 
221
- with click.progressbar(
222
- length=left,
223
- label=label,
224
- fill_char=click.style("#", fg="green"),
225
- empty_char=click.style("-", fg="red"),
226
- item_show_func=display_status,
227
- ) as pb:
254
+ if use_stderr:
255
+ # When using stderr for logs, avoid an interactive progress bar and just poll for status.
228
256
  while True:
229
257
  res = get_package_status(owner, repo, slug)
230
- ok, failed, progress, status_str, stage_str, reason = res
231
- progress = max(1, progress)
232
- delta = progress - last_progress
233
- pb.update(delta)
234
- if delta > 0:
235
- last_progress = progress
236
- left -= delta
258
+ ok, failed, _, _, _, _ = res
237
259
  if ok or failed:
238
260
  break
239
- if first:
240
- first = False
241
- else:
242
- # Sleep, but only after the first status call
261
+
262
+ # Sleep if we are going to loop again
263
+ if not first:
243
264
  time.sleep(total_wait_interval)
244
265
  total_wait_interval = min(
245
266
  300.0, total_wait_interval + wait_interval
246
267
  )
268
+ first = False
247
269
 
248
- if left > 0:
249
- pb.update(left)
270
+ else:
271
+ with click.progressbar(
272
+ length=left,
273
+ label=label,
274
+ fill_char=click.style("#", fg="green"),
275
+ empty_char=click.style("-", fg="red"),
276
+ item_show_func=display_status,
277
+ ) as pb:
278
+ while True:
279
+ res = get_package_status(owner, repo, slug)
280
+ ok, failed, progress, status_str, stage_str, reason = res
281
+ progress = max(1, progress)
282
+ delta = progress - last_progress
283
+ pb.update(delta)
284
+ if delta > 0:
285
+ last_progress = progress
286
+ left -= delta
287
+ if ok or failed:
288
+ break
289
+ if first:
290
+ first = False
291
+ else:
292
+ # Sleep, but only after the first status call
293
+ time.sleep(total_wait_interval)
294
+ total_wait_interval = min(
295
+ 300.0, total_wait_interval + wait_interval
296
+ )
297
+
298
+ if left > 0:
299
+ pb.update(left)
250
300
 
251
301
  end = datetime.now()
252
302
  seconds = (end - start).total_seconds()
253
303
 
254
- click.echo()
304
+ click.echo(err=use_stderr)
255
305
 
256
306
  if ok:
257
307
  click.secho(
258
308
  "Package synchronised successfully in %(seconds)s second(s)!"
259
309
  % {"seconds": click.style(str(seconds), bold=True)},
260
310
  fg="green",
311
+ err=use_stderr,
261
312
  )
262
313
  return
263
314
 
@@ -268,21 +319,25 @@ def wait_for_package_sync(
268
319
  "stage": click.style(stage_str or "Unknown", fg="yellow"),
269
320
  },
270
321
  fg="red",
322
+ err=use_stderr,
271
323
  )
272
324
 
273
325
  if reason:
274
326
  click.secho(
275
327
  f"Reason given: {click.style(reason, fg='yellow')}",
276
328
  fg="red",
329
+ err=use_stderr,
277
330
  )
278
331
 
279
332
  # pylint: disable=fixme
280
333
  # FIXME: The API should communicate "no retry" fails
281
334
  if "package should be deleted" in reason and attempts > 1:
282
335
  click.secho(
283
- "This is not recoverable, so stopping further attempts!", fg="red"
336
+ "This is not recoverable, so stopping further attempts!",
337
+ fg="red",
338
+ err=use_stderr,
284
339
  )
285
- click.echo()
340
+ click.echo(err=use_stderr)
286
341
  attempts = 0
287
342
 
288
343
  if attempts + 1 > 0:
@@ -292,9 +347,10 @@ def wait_for_package_sync(
292
347
  % {
293
348
  "left": click.style(str(attempts), bold=True),
294
349
  "action": "trying again" if attempts > 0 else "giving up",
295
- }
350
+ },
351
+ err=use_stderr,
296
352
  )
297
- click.echo()
353
+ click.echo(err=use_stderr)
298
354
 
299
355
  if attempts > 0:
300
356
  from .resync import resync_package
@@ -418,7 +474,7 @@ def upload_files_and_create_package(
418
474
  ]
419
475
 
420
476
  # 4. Create the package with package files and additional arguments
421
- _, slug = create_package(
477
+ slug_perm, slug = create_package(
422
478
  ctx=ctx,
423
479
  opts=opts,
424
480
  owner=owner,
@@ -429,7 +485,7 @@ def upload_files_and_create_package(
429
485
  )
430
486
 
431
487
  if no_wait_for_sync:
432
- return
488
+ return slug_perm, slug
433
489
 
434
490
  # 5. (optionally) Wait for the package to synchronise
435
491
  wait_for_package_sync(
@@ -443,6 +499,8 @@ def upload_files_and_create_package(
443
499
  attempts=sync_attempts,
444
500
  )
445
501
 
502
+ return slug_perm, slug
503
+
446
504
 
447
505
  def create_push_handlers():
448
506
  """Create a handler for upload per package format."""
@@ -530,6 +588,7 @@ def create_push_handlers():
530
588
  @click.pass_context
531
589
  def push_handler(ctx, *args, **kwargs):
532
590
  """Handle upload for a specific package format."""
591
+ opts = kwargs.get("opts")
533
592
  parameters = context.get(ctx.info_name)
534
593
  kwargs["package_type"] = ctx.info_name
535
594
 
@@ -543,16 +602,39 @@ def create_push_handlers():
543
602
  if not isinstance(package_files, tuple):
544
603
  package_files = (package_files,)
545
604
 
605
+ results = []
546
606
  for package_file in package_files:
547
607
  kwargs["package_file"] = package_file
548
608
 
549
609
  try:
550
- click.echo()
551
- upload_files_and_create_package(ctx, *args, **kwargs)
610
+ click.echo(err=utils.should_use_stderr(opts))
611
+ res = upload_files_and_create_package(ctx, *args, **kwargs)
612
+ if res:
613
+ results.append(res)
552
614
  except ApiException:
553
- click.secho("Skipping error and moving on.", fg="yellow")
615
+ click.secho(
616
+ "Skipping error and moving on.",
617
+ fg="yellow",
618
+ err=utils.should_use_stderr(opts),
619
+ )
554
620
 
555
- click.echo()
621
+ click.echo(err=utils.should_use_stderr(opts))
622
+
623
+ if utils.should_use_stderr(opts):
624
+ data = []
625
+ for slug_perm, slug in results:
626
+ data.append(
627
+ {
628
+ "slug_perm": slug_perm,
629
+ "slug": slug,
630
+ "status": "OK", # Assuming success if we got here
631
+ }
632
+ )
633
+
634
+ if len(data) == 1:
635
+ utils.maybe_print_as_json(opts, data[0])
636
+ else:
637
+ utils.maybe_print_as_json(opts, data)
556
638
 
557
639
  # Add any additional arguments
558
640
  for k, info in kwargs.items():
@@ -5,7 +5,7 @@ import functools
5
5
  import click
6
6
 
7
7
  from ...core.api import packages as api
8
- from .. import command, decorators, validators
8
+ from .. import command, decorators, utils, validators
9
9
  from ..exceptions import handle_api_exceptions
10
10
  from ..utils import maybe_spinner
11
11
  from .main import main
@@ -69,8 +69,7 @@ def add_quarantine(ctx, opts, owner_repo_package, page, page_size, page_all):
69
69
  """
70
70
  owner, repo, slug = owner_repo_package
71
71
 
72
- # Use stderr for messages if the output is something else (e.g. # JSON)
73
- use_stderr = opts.output != "pretty"
72
+ use_stderr = utils.should_use_stderr(opts)
74
73
 
75
74
  click.echo(
76
75
  "Adding %(repository)s/%(package_slug)s to quarantine... "
@@ -89,6 +88,8 @@ def add_quarantine(ctx, opts, owner_repo_package, page, page_size, page_all):
89
88
 
90
89
  click.secho("OK", fg="green", err=use_stderr)
91
90
 
91
+ utils.maybe_print_status_json(opts, {"slug": slug, "status": "OK"})
92
+
92
93
 
93
94
  @quarantine.command(name="add")
94
95
  @common_quarantine_options
@@ -117,7 +118,7 @@ def remove_quarantine(ctx, opts, owner_repo_package, page, page_size, page_all):
117
118
  owner, repo, slug = owner_repo_package
118
119
 
119
120
  # Use stderr for messages if the output is something else (e.g. # JSON)
120
- use_stderr = opts.output != "pretty"
121
+ use_stderr = utils.should_use_stderr(opts)
121
122
 
122
123
  click.echo(
123
124
  "Removing %(repository)s/%(package_slug)s from quarantine... "
@@ -136,6 +137,8 @@ def remove_quarantine(ctx, opts, owner_repo_package, page, page_size, page_all):
136
137
 
137
138
  click.secho("OK", fg="green", err=use_stderr)
138
139
 
140
+ utils.maybe_print_status_json(opts, {"slug": slug, "status": "OK"})
141
+
139
142
 
140
143
  @quarantine.command(name="remove", aliases=["rm", "restore"])
141
144
  @common_quarantine_options
@@ -104,7 +104,7 @@ def usage(ctx, opts, owner, oss):
104
104
  """
105
105
 
106
106
  # Use stderr for messages if the output is something else (e.g. # JSON)
107
- use_stderr = opts.output != "pretty"
107
+ use_stderr = utils.should_use_stderr(opts)
108
108
  click.echo("Getting quota ... ", nl=False, err=use_stderr)
109
109
 
110
110
  owner = owner[0]
@@ -89,7 +89,7 @@ def usage(ctx, opts, owner, oss):
89
89
  """
90
90
 
91
91
  # Use stderr for messages if the output is something else (e.g. # JSON)
92
- use_stderr = opts.output != "pretty"
92
+ use_stderr = utils.should_use_stderr(opts)
93
93
  click.echo("Getting quota ... ", nl=False, err=use_stderr)
94
94
 
95
95
  owner = owner[0]
@@ -104,7 +104,7 @@ def get(ctx, opts, owner_repo, page, page_size, page_all):
104
104
  (if any). If you're unauthenticated, no results will be returned.
105
105
  """
106
106
  # Use stderr for messages if the output is something else (e.g. JSON)
107
- use_stderr = opts.output != "pretty"
107
+ use_stderr = utils.should_use_stderr(opts)
108
108
 
109
109
  if isinstance(owner_repo, list):
110
110
  if len(owner_repo) == 1:
@@ -181,7 +181,7 @@ def create(ctx, opts, owner, repo_config_file):
181
181
  $ cloudsmith repos create your-org repo-config-file.json
182
182
  """
183
183
  # Use stderr for messages if the output is something else (e.g. JSON)
184
- use_stderr = opts.output != "pretty"
184
+ use_stderr = utils.should_use_stderr(opts)
185
185
  repo_config = json.load(repo_config_file)
186
186
 
187
187
  repo_name = repo_config.get("name", None)
@@ -312,7 +312,9 @@ def delete(ctx, opts, owner_repo, yes):
312
312
  }
313
313
 
314
314
  prompt = "delete the %(repository)s from the %(namespace)s namespace" % delete_args
315
- if not utils.confirm_operation(prompt, assume_yes=yes):
315
+ # Use stderr for messages if the output is something else (e.g. JSON)
316
+ use_stderr = utils.should_use_stderr(opts)
317
+ if not utils.confirm_operation(prompt, assume_yes=yes, err=use_stderr):
316
318
  return
317
319
 
318
320
  click.secho(
@@ -3,7 +3,7 @@
3
3
  import click
4
4
 
5
5
  from ...core.api.packages import resync_package as api_resync_package
6
- from .. import decorators, validators
6
+ from .. import decorators, utils, validators
7
7
  from ..exceptions import handle_api_exceptions
8
8
  from ..utils import maybe_spinner
9
9
  from .main import main
@@ -53,6 +53,7 @@ def resync(
53
53
  )
54
54
 
55
55
  if no_wait_for_sync:
56
+ utils.maybe_print_status_json(opts, {"slug": slug, "status": "OK"})
56
57
  return
57
58
 
58
59
  wait_for_package_sync(
@@ -66,13 +67,17 @@ def resync(
66
67
  attempts=sync_attempts,
67
68
  )
68
69
 
70
+ utils.maybe_print_status_json(opts, {"slug": slug, "status": "OK"})
71
+
69
72
 
70
73
  def resync_package(ctx, opts, owner, repo, slug, skip_errors):
71
74
  """Resynchronise a package."""
75
+ use_stderr = utils.should_use_stderr(opts)
72
76
  click.echo(
73
77
  "Resynchonising the %(slug)s package ... "
74
78
  % {"slug": click.style(slug, bold=True)},
75
79
  nl=False,
80
+ err=use_stderr,
76
81
  )
77
82
 
78
83
  context_msg = "Failed to resynchronise package!"
@@ -82,4 +87,4 @@ def resync_package(ctx, opts, owner, repo, slug, skip_errors):
82
87
  with maybe_spinner(opts):
83
88
  api_resync_package(owner=owner, repo=repo, identifier=slug)
84
89
 
85
- click.secho("OK", fg="green")
90
+ click.secho("OK", fg="green", err=use_stderr)