-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy path__init__.py
More file actions
192 lines (166 loc) · 6.18 KB
/
Copy path__init__.py
File metadata and controls
192 lines (166 loc) · 6.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# (C) Datadog, Inc. 2022-present
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)
import os
import click
import pluggy
from datadog_checks.dev.tooling.commands.run import run
from ddev._version import __version__
from ddev.cli import upgrade_check
from ddev.cli.application import Application, DdevGroup
from ddev.cli.ci import ci
from ddev.cli.clean import clean
from ddev.cli.config import config
from ddev.cli.create import create
from ddev.cli.dep import dep
from ddev.cli.docs import docs
from ddev.cli.env import env
from ddev.cli.meta import meta
from ddev.cli.release import release
from ddev.cli.size import size
from ddev.cli.status import status
from ddev.cli.test import test
from ddev.cli.validate import validate
from ddev.config.constants import AppEnvVars, ConfigEnvVars
from ddev.plugin import specs
from ddev.utils.ci import running_in_ci
from ddev.utils.fs import Path
from ddev.utils.github_errors import GitHubAuthenticationError
def _display_registered_exception(app: Application, error: Exception) -> None:
app.display_error(str(error))
@click.group(cls=DdevGroup, context_settings={'help_option_names': ['-h', '--help']}, invoke_without_command=True)
@click.option('--core', '-c', is_flag=True, help='Work on `integrations-core`.')
@click.option('--extras', '-e', is_flag=True, help='Work on `integrations-extras`.')
@click.option('--marketplace', '-m', is_flag=True, help='Work on `marketplace`.')
@click.option('--agent', '-a', is_flag=True, help='Work on `datadog-agent`.')
@click.option('--here', '-x', is_flag=True, help='Work on the current location.')
@click.option('--org', '-o', default=None, help='Override org config field for this invocation.')
@click.option(
'--color/--no-color',
default=None,
help='Whether or not to display colored output (default is auto-detection) [env vars: `FORCE_COLOR`/`NO_COLOR`]',
)
@click.option(
'--interactive/--no-interactive',
envvar=AppEnvVars.INTERACTIVE,
default=None,
help=(
'Whether or not to allow features like prompts and progress bars (default is auto-detection) '
'[env var: `DDEV_INTERACTIVE`]'
),
)
@click.option(
'--verbose',
'-v',
envvar=AppEnvVars.VERBOSE,
count=True,
help='Increase verbosity (can be used additively) [env var: `DDEV_VERBOSE`]',
)
@click.option(
'--quiet',
'-q',
envvar=AppEnvVars.QUIET,
count=True,
help='Decrease verbosity (can be used additively) [env var: `DDEV_QUIET`]',
)
@click.option(
'--config',
'config_file',
envvar=ConfigEnvVars.CONFIG,
help='The path to a custom config file to use [env var: `DDEV_CONFIG`]',
)
@click.version_option(version=__version__, prog_name='ddev')
@click.pass_context
def ddev(
ctx: click.Context, core, extras, marketplace, agent, here, org, color, interactive, verbose, quiet, config_file
):
"""
\b
_ _
__| | __| | _____ __
/ _` |/ _` |/ _ \\ \\ / /
| (_| | (_| | __/\\ V /
\\__,_|\\__,_|\\___| \\_/
"""
if color is None:
if os.environ.get(AppEnvVars.NO_COLOR) == '1':
color = False
elif os.environ.get(AppEnvVars.FORCE_COLOR) == '1':
color = True
if interactive is None:
interactive = not running_in_ci()
app = Application(ctx.exit, verbose - quiet, color, interactive)
app.register_exception_handler(GitHubAuthenticationError, _display_registered_exception)
if config_file:
app.config_file.path = Path(config_file).resolve()
if not app.config_file.global_path.is_file():
app.abort(f'The selected config file `{str(app.config_file.path)}` does not exist.')
elif not app.config_file.global_path.is_file():
if app.verbose:
app.display_waiting('No config file found, creating one with default settings now...')
try:
app.config_file.restore()
if app.verbose:
app.display_success('Success! Please see `ddev config`.')
except OSError: # no cov
app.abort(
f'Unable to create config file located at `{str(app.config_file.global_path)}`.'
'Please check your permissions.'
)
if app.verbose:
if app.config_file.overrides_available():
app.display_info('Local override config file found. Values from this file will override global values.')
if org is not None:
app.config.org = org
if not ctx.invoked_subcommand:
app.display_info(ctx.get_help(), highlight=False)
return
# Persist app data for sub-commands
ctx.obj = app
try:
app.config_file.load()
except OSError as e: # no cov
app.abort(f'Error loading configuration: {e}')
if app.config.upgrade_check:
upgrade_check.upgrade_check(app, __version__)
if not ctx.invoked_subcommand:
app.display_info(ctx.get_help(), highlight=False)
return
app.config.terminal.styles.parse_fields()
errors = app.initialize_styles(app.config.terminal.styles.raw_data)
if errors and color is not False and not app.quiet: # no cov
for error in errors:
app.display_warning(error)
# Do this last
app.set_repo(core, extras, marketplace, agent, here)
# TODO: remove this when the old CLI is gone
app.initialize_old_cli()
ddev.add_command(ci)
ddev.add_command(clean)
ddev.add_command(config)
ddev.add_command(create)
ddev.add_command(dep)
ddev.add_command(docs)
ddev.add_command(env)
ddev.add_command(meta)
ddev.add_command(release)
ddev.add_command(run)
ddev.add_command(status)
ddev.add_command(test)
ddev.add_command(validate)
ddev.add_command(size)
__management_command = os.environ.get('PYAPP_COMMAND_NAME', '')
if __management_command:
ddev.add_command(click.Command(name=__management_command, help='Manage this application'))
def main(): # no cov
manager = pluggy.PluginManager('ddev')
manager.add_hookspecs(specs)
manager.load_setuptools_entrypoints('ddev')
manager.hook.register_commands()
try:
return ddev(prog_name='ddev', windows_expand_args=False)
except Exception:
from rich.console import Console
console = Console()
console.print_exception(suppress=[click])
return 1