File tree 2 files changed +22
-2
lines changed
2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change 96
96
opt_username ,
97
97
opt_yes_no ,
98
98
)
99
- from .commands .cli .util import recast_exceptions_to_click
99
+ from .commands .cli .util import recast_exceptions_to_click , monkeypatch_hide_click_cmd_options
100
100
from planet_auth_utils .constants import EnvironmentVariables
101
101
from planet_auth_utils .plauth_factory import PlanetAuthFactory
102
102
from planet_auth_utils .builtins import Builtins
158
158
"opt_token_file" ,
159
159
"opt_username" ,
160
160
"opt_yes_no" ,
161
+ #
161
162
"recast_exceptions_to_click" ,
163
+ "monkeypatch_hide_click_cmd_options" ,
162
164
#
163
165
"Builtins" ,
164
166
"EnvironmentVariables" ,
Original file line number Diff line number Diff line change 15
15
import click
16
16
import functools
17
17
import json
18
- from typing import Optional
18
+ from typing import List , Optional
19
19
20
20
import planet_auth
21
21
from planet_auth .constants import AUTH_CONFIG_FILE_SOPS , AUTH_CONFIG_FILE_PLAIN
26
26
from .prompts import prompt_and_change_user_default_profile_if_different
27
27
28
28
29
+ def monkeypatch_hide_click_cmd_options (cmd , hide_options : List [str ]):
30
+ """
31
+ Monkey patch a click command to hide the specified command options.
32
+ Useful when reusing click commands in contexts where you do not
33
+ wish to expose all the options.
34
+ """
35
+ for hide_option in hide_options :
36
+ for param in cmd .params :
37
+ if param .name == hide_option :
38
+ param .hidden = True
39
+ break
40
+
41
+
29
42
def recast_exceptions_to_click (* exceptions , ** params ): # pylint: disable=W0613
43
+ """
44
+ Decorator to catch exceptions and raise them as ClickExceptions.
45
+ Useful to apply to `click` commands to supress stack traces that
46
+ might be otherwise exposed to the end-user.
47
+ """
30
48
if not exceptions :
31
49
exceptions = (Exception ,)
32
50
# params.get('some_arg', 'default')
You can’t perform that action at this time.
0 commit comments