Skip to content

Commit 344cc9f

Browse files
clean up option defaults
1 parent bc7dccd commit 344cc9f

File tree

1 file changed

+40
-40
lines changed

1 file changed

+40
-40
lines changed

src/planet_auth_utils/commands/cli/options.py

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424

2525

2626
# TODO: make default, hidden, required params for everyone. Fix monkey patching, if needed
27-
# TODO: sort members
28-
def opt_api_key() -> _click_option_decorator_type:
27+
def opt_api_key(default=None) -> _click_option_decorator_type:
2928
"""
3029
Click option for specifying an API key
3130
"""
@@ -36,7 +35,7 @@ def decorator(function) -> _click_option_decorator_type:
3635
type=str,
3736
envvar=EnvironmentVariables.AUTH_API_KEY,
3837
help="Specify an API key.",
39-
default=None,
38+
default=default,
4039
show_envvar=True,
4140
show_default=True,
4241
)(function)
@@ -45,7 +44,7 @@ def decorator(function) -> _click_option_decorator_type:
4544
return decorator
4645

4746

48-
def opt_audience(required=False) -> _click_option_decorator_type:
47+
def opt_audience(default=None, required=False) -> _click_option_decorator_type:
4948
"""
5049
Click option for specifying an OAuth token audience for the
5150
planet_auth package's click commands.
@@ -60,7 +59,7 @@ def decorator(function) -> _click_option_decorator_type:
6059
help="Token audiences. Specify multiple options to set"
6160
" multiple audiences. When set via environment variable, audiences"
6261
" should be white space delimited.",
63-
default=None,
62+
default=default,
6463
show_envvar=True,
6564
show_default=True,
6665
required=required,
@@ -70,7 +69,7 @@ def decorator(function) -> _click_option_decorator_type:
7069
return decorator
7170

7271

73-
def opt_client_id() -> _click_option_decorator_type:
72+
def opt_client_id(default=None) -> _click_option_decorator_type:
7473
"""
7574
Click option for specifying an OAuth client ID.
7675
"""
@@ -81,7 +80,7 @@ def decorator(function) -> _click_option_decorator_type:
8180
type=str,
8281
envvar=EnvironmentVariables.AUTH_CLIENT_ID,
8382
help="Specify the OAuth client ID.",
84-
default=None,
83+
default=default,
8584
show_envvar=True,
8685
show_default=True,
8786
)(function)
@@ -90,7 +89,7 @@ def decorator(function) -> _click_option_decorator_type:
9089
return decorator
9190

9291

93-
def opt_client_secret() -> _click_option_decorator_type:
92+
def opt_client_secret(default=None) -> _click_option_decorator_type:
9493
"""
9594
Click option for specifying an OAuth client secret.
9695
"""
@@ -101,7 +100,7 @@ def decorator(function) -> _click_option_decorator_type:
101100
type=str,
102101
envvar=EnvironmentVariables.AUTH_CLIENT_SECRET,
103102
help="Specify the OAuth client Secret.",
104-
default=None,
103+
default=default,
105104
show_envvar=True,
106105
show_default=True,
107106
)(function)
@@ -110,7 +109,7 @@ def decorator(function) -> _click_option_decorator_type:
110109
return decorator
111110

112111

113-
def opt_extra() -> _click_option_decorator_type:
112+
def opt_extra(default=None) -> _click_option_decorator_type:
114113
"""
115114
Click option for specifying extra options.
116115
"""
@@ -126,7 +125,7 @@ def decorator(function) -> _click_option_decorator_type:
126125
" multiple extra options. The format of an option is <key>=<value>."
127126
" When set via environment variable, values should be delimited by"
128127
" whitespace.",
129-
default=None,
128+
default=default,
130129
show_envvar=True,
131130
show_default=True,
132131
)(function)
@@ -135,7 +134,7 @@ def decorator(function) -> _click_option_decorator_type:
135134
return decorator
136135

137136

138-
def opt_human_readable() -> _click_option_decorator_type:
137+
def opt_human_readable(default=False) -> _click_option_decorator_type:
139138
"""
140139
Click option to toggle raw / human-readable formatting.
141140
"""
@@ -145,15 +144,15 @@ def decorator(function) -> _click_option_decorator_type:
145144
"--human-readable/--no-human-readable",
146145
"-H",
147146
help="Reformat fields to be human readable.",
148-
default=False,
147+
default=default,
149148
show_default=True,
150149
)(function)
151150
return function
152151

153152
return decorator
154153

155154

156-
def opt_issuer(required=False) -> _click_option_decorator_type:
155+
def opt_issuer(default=None, required=False) -> _click_option_decorator_type:
157156
"""
158157
Click option for specifying an OAuth token issuer for the
159158
planet_auth package's click commands.
@@ -165,7 +164,7 @@ def decorator(function) -> _click_option_decorator_type:
165164
type=str,
166165
envvar=EnvironmentVariables.AUTH_ISSUER,
167166
help="Token issuer.",
168-
default=None,
167+
default=default,
169168
show_envvar=False,
170169
show_default=False,
171170
required=required,
@@ -175,7 +174,7 @@ def decorator(function) -> _click_option_decorator_type:
175174
return decorator
176175

177176

178-
def opt_loglevel() -> _click_option_decorator_type:
177+
def opt_loglevel(default="INFO") -> _click_option_decorator_type:
179178
"""
180179
Click option for specifying a log level.
181180
"""
@@ -187,7 +186,7 @@ def decorator(function) -> _click_option_decorator_type:
187186
envvar=EnvironmentVariables.AUTH_LOGLEVEL,
188187
help="Set the log level.",
189188
type=click.Choice(["CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG"], case_sensitive=False),
190-
default="INFO",
189+
default=default,
191190
show_envvar=True,
192191
show_default=True,
193192
)(function)
@@ -196,7 +195,7 @@ def decorator(function) -> _click_option_decorator_type:
196195
return decorator
197196

198197

199-
def opt_long() -> _click_option_decorator_type:
198+
def opt_long(default=False) -> _click_option_decorator_type:
200199
"""
201200
Click option specifying that long or more detailed output should be produced.
202201
"""
@@ -207,15 +206,15 @@ def decorator(function) -> _click_option_decorator_type:
207206
"--long",
208207
help="Longer, more detailed output",
209208
is_flag=True,
210-
default=False,
209+
default=default,
211210
show_default=True,
212211
)(function)
213212
return function
214213

215214
return decorator
216215

217216

218-
def opt_open_browser() -> _click_option_decorator_type:
217+
def opt_open_browser(default=True) -> _click_option_decorator_type:
219218
"""
220219
Click option for specifying whether or not opening a browser is permitted
221220
for the planet_auth package's click commands.
@@ -225,7 +224,7 @@ def decorator(function) -> _click_option_decorator_type:
225224
function = click.option(
226225
"--open-browser/--no-open-browser",
227226
help="Allow/Suppress the automatic opening of a browser window.",
228-
default=True,
227+
default=default,
229228
show_default=True,
230229
)(function)
231230
return function
@@ -260,7 +259,7 @@ def decorator(function) -> _click_option_decorator_type:
260259
# I generally think user IO belongs with the app, and not the the library, but since the
261260
# lib also handles things like browser interaction this is not entirely easy to abstract
262261
# away.
263-
def opt_password(hidden=True) -> _click_option_decorator_type:
262+
def opt_password(default=None, hidden=True) -> _click_option_decorator_type:
264263
"""
265264
Click option for specifying a password for the
266265
planet_auth package's click commands.
@@ -272,7 +271,7 @@ def decorator(function) -> _click_option_decorator_type:
272271
type=str,
273272
envvar=EnvironmentVariables.AUTH_PASSWORD,
274273
help="Password used for authentication. May not be used by all authentication mechanisms.",
275-
default=None,
274+
default=default,
276275
show_envvar=True,
277276
show_default=True,
278277
hidden=hidden, # Primarily used by legacy auth. OAuth2 is preferred, wherein we do not handle username/password.
@@ -311,7 +310,7 @@ def decorator(function) -> _click_option_decorator_type:
311310
return decorator
312311

313312

314-
def opt_project() -> _click_option_decorator_type:
313+
def opt_project(default=None) -> _click_option_decorator_type:
315314
"""
316315
Click option for specifying a project ID.
317316
"""
@@ -324,7 +323,7 @@ def decorator(function) -> _click_option_decorator_type:
324323
# envvar=EnvironmentVariables.AUTH_PROJECT,
325324
help="Project ID to use when performing authentication. When present, this option will be"
326325
" appended to authorization requests. Not all implementations understand this option.",
327-
default=None,
326+
default=default,
328327
show_envvar=True,
329328
show_default=True,
330329
)(function)
@@ -333,7 +332,7 @@ def decorator(function) -> _click_option_decorator_type:
333332
return decorator
334333

335334

336-
def opt_qr_code() -> _click_option_decorator_type:
335+
def opt_qr_code(default=False) -> _click_option_decorator_type:
337336
"""
338337
Click option for specifying whether a QR code should be displayed.
339338
"""
@@ -342,15 +341,15 @@ def decorator(function) -> _click_option_decorator_type:
342341
function = click.option(
343342
"--show-qr-code/--no-show-qr-code",
344343
help="Control whether a QR code is displayed for the user.",
345-
default=False,
344+
default=default,
346345
show_default=True,
347346
)(function)
348347
return function
349348

350349
return decorator
351350

352351

353-
def opt_refresh() -> _click_option_decorator_type:
352+
def opt_refresh(default=True) -> _click_option_decorator_type:
354353
"""
355354
Click option specifying a refresh should be attempted if applicable.
356355
"""
@@ -359,15 +358,15 @@ def decorator(function) -> _click_option_decorator_type:
359358
function = click.option(
360359
"--refresh/--no-refresh",
361360
help="Automatically perform a credential refresh if required.",
362-
default=True,
361+
default=default,
363362
show_default=True,
364363
)(function)
365364
return function
366365

367366
return decorator
368367

369368

370-
def opt_token() -> _click_option_decorator_type:
369+
def opt_token(default=None) -> _click_option_decorator_type:
371370
"""
372371
Click option for specifying a token literal.
373372
"""
@@ -376,6 +375,7 @@ def decorator(function) -> _click_option_decorator_type:
376375
function = click.option(
377376
"--token",
378377
help="Token string.",
378+
default=default,
379379
type=str,
380380
# envvar=EnvironmentVariables.AUTH_TOKEN,
381381
show_envvar=False,
@@ -386,7 +386,7 @@ def decorator(function) -> _click_option_decorator_type:
386386
return decorator
387387

388388

389-
def opt_scope() -> _click_option_decorator_type:
389+
def opt_scope(default=None) -> _click_option_decorator_type:
390390
"""
391391
Click option for specifying an OAuth token scope for the
392392
planet_auth package's click commands.
@@ -402,7 +402,7 @@ def decorator(function) -> _click_option_decorator_type:
402402
" multiple scopes. When set via environment variable, scopes"
403403
" should be white space delimited. Default value is determined"
404404
" by the selected auth profile.",
405-
default=None,
405+
default=default,
406406
show_envvar=True,
407407
show_default=True,
408408
)(function)
@@ -411,7 +411,7 @@ def decorator(function) -> _click_option_decorator_type:
411411
return decorator
412412

413413

414-
def opt_sops() -> _click_option_decorator_type:
414+
def opt_sops(default=False) -> _click_option_decorator_type:
415415
"""
416416
Click option specifying that SOPS should be used.
417417
"""
@@ -421,15 +421,15 @@ def decorator(function) -> _click_option_decorator_type:
421421
"--sops/--no-sops",
422422
help="Use sops when creating new files where applicable."
423423
" The environment must be configured for SOPS to work by default.",
424-
default=False,
424+
default=default,
425425
show_default=True,
426426
)(function)
427427
return function
428428

429429
return decorator
430430

431431

432-
def opt_token_file() -> _click_option_decorator_type:
432+
def opt_token_file(default=None) -> _click_option_decorator_type:
433433
"""
434434
Click option for specifying a token file location for the
435435
planet_auth package's click commands.
@@ -441,7 +441,7 @@ def decorator(function) -> _click_option_decorator_type:
441441
type=click.Path(exists=True, file_okay=True, readable=True, path_type=pathlib.Path),
442442
envvar=EnvironmentVariables.AUTH_TOKEN_FILE,
443443
help="File containing a token.",
444-
default=None,
444+
default=default,
445445
show_envvar=False,
446446
show_default=True,
447447
)(function)
@@ -450,7 +450,7 @@ def decorator(function) -> _click_option_decorator_type:
450450
return decorator
451451

452452

453-
def opt_username(hidden=True) -> _click_option_decorator_type:
453+
def opt_username(default=None, hidden=True) -> _click_option_decorator_type:
454454
"""
455455
Click option for specifying a username for the
456456
planet_auth package's click commands.
@@ -463,7 +463,7 @@ def decorator(function) -> _click_option_decorator_type:
463463
type=str,
464464
envvar=EnvironmentVariables.AUTH_USERNAME,
465465
help="Username used for authentication. May not be used by all authentication mechanisms.",
466-
default=None,
466+
default=default,
467467
show_envvar=True,
468468
show_default=True,
469469
hidden=hidden, # Primarily used by legacy auth. OAuth2 is preferred, wherein we do not handle username/password.
@@ -473,7 +473,7 @@ def decorator(function) -> _click_option_decorator_type:
473473
return decorator
474474

475475

476-
def opt_yes_no() -> _click_option_decorator_type:
476+
def opt_yes_no(default=None) -> _click_option_decorator_type:
477477
"""
478478
Click option to bypass prompts with a yes or no selection.
479479
"""
@@ -483,7 +483,7 @@ def decorator(function) -> _click_option_decorator_type:
483483
"--yes/--no",
484484
"-y/-n",
485485
help='Skip user prompts with a "yes" or "no" selection',
486-
default=None,
486+
default=default,
487487
show_default=True,
488488
)(function)
489489
return function

0 commit comments

Comments
 (0)