-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathproject.py
More file actions
148 lines (120 loc) · 4.76 KB
/
Copy pathproject.py
File metadata and controls
148 lines (120 loc) · 4.76 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
from typing import Optional
import typer
from arcade_cli.authn import fetch_projects
from arcade_cli.console import console
from arcade_cli.usage.command_tracker import TrackedTyper, TrackedTyperGroup
from arcade_cli.utils import (
handle_cli_error,
resolve_coordinator_url,
)
app = TrackedTyper(
cls=TrackedTyperGroup,
add_completion=False,
no_args_is_help=True,
pretty_exceptions_enable=True,
pretty_exceptions_show_locals=False,
pretty_exceptions_short=True,
)
state: dict[str, str] = {}
@app.callback()
def main(
host: Optional[str] = typer.Option(
None,
"--host",
"-h",
help=(
"The Arcade Coordinator host. Defaults to the host from `arcade login`, "
"then `cloud.arcade.dev`."
),
),
port: Optional[int] = typer.Option(
None,
"--port",
"-p",
help="The port of the Arcade Coordinator host.",
),
force_tls: bool = typer.Option(
False,
"--tls",
help="Whether to force TLS for the connection to Arcade Coordinator.",
),
force_no_tls: bool = typer.Option(
False,
"--no-tls",
help="Whether to disable TLS for the connection to Arcade Coordinator.",
),
) -> None:
"""Configure Coordinator connection options for project commands."""
state["coordinator_url"] = resolve_coordinator_url(host, port, force_tls, force_no_tls)
@app.command("list", help="List projects in the active organization")
def project_list(
debug: bool = typer.Option(False, "--debug", "-d", help="Show debug information"),
) -> None:
"""List all projects in the current active organization."""
from arcade_core.config_model import Config
from rich.table import Table
try:
config = Config.load_from_file()
if not config.context:
console.print("No active organization set. Run 'arcade login' first.", style="bold red")
return
coordinator_url = state["coordinator_url"]
projects = fetch_projects(coordinator_url, config.context.org_id)
if not projects:
console.print(
f"No projects found in organization '{config.context.org_name}'.",
style="yellow",
)
return
active_project_id = config.get_active_project_id()
console.print(
f"\nActive organization: {config.context.org_name}\n"
"Use 'arcade org list' and 'arcade org set <org_id>' to switch organizations.\n",
)
table = Table()
table.add_column("Name", style="cyan")
table.add_column("ID", style="dim")
table.add_column("Default", style="green")
table.add_column("Active", style="bold yellow")
for project in projects:
is_active = "✓" if project.project_id == active_project_id else ""
is_default = "✓" if project.is_default else ""
table.add_row(project.name, project.project_id, is_default, is_active)
console.print(table)
console.print("\nUse 'arcade project set <project_id>' to switch projects.\n")
except ValueError as e:
handle_cli_error(str(e))
except Exception as e:
handle_cli_error("Failed to list projects", e, debug)
@app.command("set", help="Set the active project")
def project_set(
project_id: str = typer.Argument(..., help="Project ID to set as active"),
debug: bool = typer.Option(False, "--debug", "-d", help="Show debug information"),
) -> None:
"""Set the active project within the current organization."""
from arcade_core.config_model import Config
try:
config = Config.load_from_file()
if not config.context:
console.print("No active organization set. Run 'arcade login' first.", style="bold red")
return
coordinator_url = state["coordinator_url"]
# Verify project exists in current org
projects = fetch_projects(coordinator_url, config.context.org_id)
target_project = next((p for p in projects if p.project_id == project_id), None)
if not target_project:
console.print(
f"Project '{project_id}' not found in organization '{config.context.org_name}'.",
style="bold red",
)
console.print("Run 'arcade project list' to see available projects.", style="dim")
return
# Update config
config.context.project_id = target_project.project_id
config.context.project_name = target_project.name
config.save_to_file()
console.print(f"✓ Switched to project: {target_project.name}", style="bold green")
except ValueError as e:
handle_cli_error(str(e))
except Exception as e:
handle_cli_error("Failed to set project", e, debug)