ml-dash 0.6.2rc1__py3-none-any.whl → 0.6.4__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.
@@ -0,0 +1,92 @@
1
+ """Profile command for ml-dash CLI - shows current user and configuration."""
2
+
3
+ import json
4
+
5
+ from rich.console import Console
6
+ from rich.panel import Panel
7
+ from rich.table import Table
8
+
9
+ from ml_dash.auth.token_storage import decode_jwt_payload, get_token_storage
10
+ from ml_dash.config import config
11
+
12
+
13
+ def add_parser(subparsers):
14
+ """Add profile command parser."""
15
+ parser = subparsers.add_parser(
16
+ "profile",
17
+ help="Show current user profile",
18
+ description="Display the current authenticated user profile and configuration.",
19
+ )
20
+ parser.add_argument(
21
+ "--json",
22
+ action="store_true",
23
+ help="Output as JSON",
24
+ )
25
+
26
+
27
+ def cmd_profile(args) -> int:
28
+ """Execute info command."""
29
+ console = Console()
30
+
31
+ # Load token
32
+ storage = get_token_storage()
33
+ token = storage.load("ml-dash-token")
34
+
35
+ import getpass
36
+
37
+ info = {
38
+ "authenticated": False,
39
+ "remote_url": config.remote_url,
40
+ "local_user": getpass.getuser(),
41
+ }
42
+
43
+ if token:
44
+ info["authenticated"] = True
45
+ info["user"] = decode_jwt_payload(token)
46
+
47
+ if args.json:
48
+ console.print_json(json.dumps(info))
49
+ return 0
50
+
51
+ # Rich display
52
+ if not info["authenticated"]:
53
+ console.print(
54
+ Panel(
55
+ f"[bold cyan]OS Username:[/bold cyan] {info.get('local_user')}\n\n"
56
+ "[yellow]Not authenticated[/yellow]\n\n"
57
+ "Run [cyan]ml-dash login[/cyan] to authenticate.",
58
+ title="[bold]ML-Dash Info[/bold]",
59
+ border_style="yellow",
60
+ )
61
+ )
62
+ return 0
63
+
64
+ # Build info table
65
+ table = Table(show_header=False, box=None, padding=(0, 2))
66
+ table.add_column("Key", style="bold cyan")
67
+ table.add_column("Value")
68
+
69
+ # table.add_row("OS Username", info.get("local_user"))
70
+ user = info.get("user", {})
71
+ if user.get("username"):
72
+ table.add_row("Username", user["username"])
73
+ else:
74
+ table.add_row("Username", "[red]Unavailable[/red]")
75
+ if user.get("sub"):
76
+ table.add_row("User ID", user["sub"])
77
+ table.add_row("Name", user.get("name") or "Unknown")
78
+ if user.get("email"):
79
+ table.add_row("Email", user["email"])
80
+ table.add_row("Remote", info.get("remote_url") or "https://api.dash.ml")
81
+ if info.get("token_expires"):
82
+ table.add_row("Token Expires", info["token_expires"])
83
+
84
+ console.print(
85
+ Panel(
86
+ table,
87
+ title="[bold green]✓ Authenticated[/bold green]",
88
+ border_style="green",
89
+ )
90
+ )
91
+
92
+ return 0