cu-cli 0.1.0b1__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.
- cu_cli/__init__.py +17 -0
- cu_cli/__main__.py +11 -0
- cu_cli/apiversion.py +124 -0
- cu_cli/cli.py +138 -0
- cu_cli/client.py +138 -0
- cu_cli/commands/__init__.py +4 -0
- cu_cli/commands/_command_spec.py +94 -0
- cu_cli/commands/_help.py +33 -0
- cu_cli/commands/_infra_models.py +184 -0
- cu_cli/commands/_infra_wizard.py +630 -0
- cu_cli/commands/_model_setup.py +46 -0
- cu_cli/commands/_options.py +112 -0
- cu_cli/commands/analyze.py +631 -0
- cu_cli/commands/analyzer.py +1462 -0
- cu_cli/commands/defaults.py +172 -0
- cu_cli/commands/doctor.py +166 -0
- cu_cli/commands/env_var.py +67 -0
- cu_cli/commands/infra.py +302 -0
- cu_cli/commands/profile_cmd.py +525 -0
- cu_cli/commands/upgrade.py +120 -0
- cu_cli/core/__init__.py +17 -0
- cu_cli/core/analyze.py +44 -0
- cu_cli/core/analyzers.py +30 -0
- cu_cli/core/azure_resources.py +486 -0
- cu_cli/core/defaults.py +18 -0
- cu_cli/core/doctor.py +42 -0
- cu_cli/core/foundry.py +68 -0
- cu_cli/core/infra_models.py +367 -0
- cu_cli/core/inputs.py +209 -0
- cu_cli/core/schema.py +24 -0
- cu_cli/errors.py +174 -0
- cu_cli/exit_codes.py +20 -0
- cu_cli/modality.py +24 -0
- cu_cli/output.py +179 -0
- cu_cli/profile.py +30 -0
- cu_cli/py.typed +0 -0
- cu_cli/resources/__init__.py +4 -0
- cu_cli/resources/azd_template/README.md +187 -0
- cu_cli/resources/azd_template/azure.yaml +27 -0
- cu_cli/resources/azd_template/hooks/postprovision.ps1 +320 -0
- cu_cli/resources/azd_template/hooks/postprovision.sh +299 -0
- cu_cli/resources/azd_template/infra/main.bicep +115 -0
- cu_cli/resources/azd_template/infra/main.parameters.json +30 -0
- cu_cli/resources/azd_template/infra/models.json +1 -0
- cu_cli/resources/azd_template/infra/modules/foundry.bicep +122 -0
- cu_cli/schema_validate.py +28 -0
- cu_cli/spec_validate.py +18 -0
- cu_cli/telemetry.py +42 -0
- cu_cli/update_check.py +154 -0
- cu_cli/update_provider.py +92 -0
- cu_cli/windows_self_upgrade.py +245 -0
- cu_cli-0.1.0b1.dist-info/METADATA +345 -0
- cu_cli-0.1.0b1.dist-info/RECORD +56 -0
- cu_cli-0.1.0b1.dist-info/WHEEL +5 -0
- cu_cli-0.1.0b1.dist-info/entry_points.txt +3 -0
- cu_cli-0.1.0b1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# Copyright (c) Microsoft Corporation.
|
|
2
|
+
# Licensed under the MIT license.
|
|
3
|
+
|
|
4
|
+
"""Shared Click option decorators and small render helpers for commands.
|
|
5
|
+
|
|
6
|
+
This is command-layer (Click) glue, deliberately kept out of ``cu_cli.core``.
|
|
7
|
+
It removes the auth-option boilerplate that was duplicated across the
|
|
8
|
+
``analyzer`` and ``defaults`` command groups.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
from contextlib import contextmanager
|
|
14
|
+
from dataclasses import dataclass
|
|
15
|
+
from time import perf_counter
|
|
16
|
+
from typing import Any, Iterator
|
|
17
|
+
|
|
18
|
+
import rich_click as click
|
|
19
|
+
|
|
20
|
+
from ..output import console
|
|
21
|
+
from ..apiversion import API_VERSION_HELP
|
|
22
|
+
|
|
23
|
+
_COMMAND_STARTED_META_KEY = "cu_command_started"
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _record_command_start(ctx: click.Context, _param: Any, value: bool) -> bool:
|
|
27
|
+
if value:
|
|
28
|
+
ctx.meta[_COMMAND_STARTED_META_KEY] = perf_counter()
|
|
29
|
+
return value
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
CALLING_TIME_OPTION = click.option(
|
|
33
|
+
"--time",
|
|
34
|
+
"show_calling_time",
|
|
35
|
+
is_flag=True,
|
|
36
|
+
callback=_record_command_start,
|
|
37
|
+
help="Show elapsed CU service and total command time on stderr.",
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
AUTH_OPTIONS = [
|
|
41
|
+
click.option("--endpoint", default=None, help="Override configured endpoint."),
|
|
42
|
+
click.option("--api-key", default=None, help="Override configured API key."),
|
|
43
|
+
click.option("--api-version", "api_version", default=None,
|
|
44
|
+
help=API_VERSION_HELP),
|
|
45
|
+
click.option(
|
|
46
|
+
"--auth-mode",
|
|
47
|
+
"entra",
|
|
48
|
+
type=click.Choice(["login", "key"]),
|
|
49
|
+
default=None,
|
|
50
|
+
help="Authentication mode; defaults to the selected CU CLI profile.",
|
|
51
|
+
),
|
|
52
|
+
click.option("-p", "--profile", "profile_name", default=None,
|
|
53
|
+
help="Named CU CLI profile to use (from cu profile)."),
|
|
54
|
+
click.option("--info", "show_runtime_context", is_flag=True,
|
|
55
|
+
help="Print resolved endpoint/auth/api-version/profile before execution."),
|
|
56
|
+
CALLING_TIME_OPTION,
|
|
57
|
+
]
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def with_auth_options(fn):
|
|
61
|
+
"""Attach the standard endpoint/auth/API/config/info/time options."""
|
|
62
|
+
for opt in reversed(AUTH_OPTIONS):
|
|
63
|
+
fn = opt(fn)
|
|
64
|
+
return fn
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
@contextmanager
|
|
68
|
+
def calling_time(enabled: bool) -> Iterator[CallingTimer]:
|
|
69
|
+
"""Measure a CU service operation; callers choose the final render point."""
|
|
70
|
+
timer = CallingTimer(enabled=enabled)
|
|
71
|
+
started = perf_counter()
|
|
72
|
+
try:
|
|
73
|
+
yield timer
|
|
74
|
+
finally:
|
|
75
|
+
timer.elapsed = perf_counter() - started
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
@dataclass
|
|
79
|
+
class CallingTimer:
|
|
80
|
+
"""Elapsed CU service time that can be rendered after command output."""
|
|
81
|
+
|
|
82
|
+
enabled: bool
|
|
83
|
+
elapsed: float | None = None
|
|
84
|
+
|
|
85
|
+
def print(self) -> None:
|
|
86
|
+
if self.enabled and self.elapsed is not None:
|
|
87
|
+
ctx = click.get_current_context(silent=True)
|
|
88
|
+
command_started = (
|
|
89
|
+
ctx.meta.get(_COMMAND_STARTED_META_KEY)
|
|
90
|
+
if ctx is not None
|
|
91
|
+
else None
|
|
92
|
+
)
|
|
93
|
+
console.print("\n")
|
|
94
|
+
console.print(
|
|
95
|
+
f"[bold cyan]CU service calling time:[/bold cyan] {self.elapsed:.3f}s",
|
|
96
|
+
highlight=False,
|
|
97
|
+
)
|
|
98
|
+
if isinstance(command_started, (int, float)):
|
|
99
|
+
total_elapsed = perf_counter() - command_started
|
|
100
|
+
console.print(
|
|
101
|
+
f"[bold cyan]Total command time:[/bold cyan] {total_elapsed:.3f}s",
|
|
102
|
+
highlight=False,
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def print_runtime_context(auth: Any, profile: Any) -> None:
|
|
107
|
+
"""Print the resolved endpoint/auth/API version/profile (the ``--info`` block)."""
|
|
108
|
+
console.print(f"[bold]endpoint:[/bold] {auth.endpoint}")
|
|
109
|
+
console.print(f"[bold]auth mode:[/bold] {auth.auth_mode}")
|
|
110
|
+
console.print(f"[bold]api-version:[/bold] {auth.api_version}")
|
|
111
|
+
console.print(f"[bold]CU CLI profile:[/bold] {profile.profile_name}")
|
|
112
|
+
console.print(f"[bold]settings:[/bold] {profile.path}")
|