Skip to content

Commit cc78118

Browse files
committed
feat(cli): add 'nf show' command to display current state
- Add new 'show' command to display current configuration - Show API key (masked), organization, team, and project - Use Rich table for better formatting - Handle errors gracefully
1 parent 7ab3e74 commit cc78118

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

infactory_client/cli.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,70 @@ def login():
148148
typer.echo(f"Failed to login: {e}", err=True)
149149
raise typer.Exit(1)
150150

151+
@app.command()
152+
def show():
153+
"""Show current state including API key (masked), organization, team, and project."""
154+
try:
155+
# Try to get client with current API key
156+
client = get_client()
157+
158+
# Get the API key (either from env or from saved file)
159+
api_key = os.getenv("NF_API_KEY") or load_api_key()
160+
161+
# Format API key for display (show only first and last few characters)
162+
masked_api_key = (
163+
f"{api_key[:7]}...{api_key[-4:]}"
164+
if api_key and len(api_key) > 11
165+
else "Not set"
166+
)
167+
168+
# Create a table for better formatting
169+
table = Table(title="Current State", show_header=False)
170+
table.add_column("Setting")
171+
table.add_column("Value")
172+
173+
# Add API key
174+
table.add_row("API Key", masked_api_key)
175+
176+
# Show organization info if set
177+
if client.state.organization_id:
178+
try:
179+
org = client.organizations.get(client.state.organization_id)
180+
table.add_row("Organization", f"{org.name} (ID: {client.state.organization_id})")
181+
except Exception:
182+
table.add_row("Organization ID", client.state.organization_id)
183+
else:
184+
table.add_row("Organization", "Not set")
185+
186+
# Show team info if set
187+
if client.state.team_id:
188+
try:
189+
team = client.teams.get(client.state.team_id)
190+
table.add_row("Team", f"{team.name} (ID: {client.state.team_id})")
191+
except Exception:
192+
table.add_row("Team ID", client.state.team_id)
193+
else:
194+
table.add_row("Team", "Not set")
195+
196+
# Show project info if set
197+
if client.state.project_id:
198+
try:
199+
project = client.projects.get(client.state.project_id)
200+
table.add_row("Project", f"{project.name} (ID: {client.state.project_id})")
201+
except Exception:
202+
table.add_row("Project ID", client.state.project_id)
203+
else:
204+
table.add_row("Project", "Not set")
205+
206+
console.print(table)
207+
208+
except ConfigError as e:
209+
typer.echo(f"Configuration error: {e}", err=True)
210+
raise typer.Exit(1)
211+
except Exception as e:
212+
typer.echo(f"Failed to show state: {e}", err=True)
213+
raise typer.Exit(1)
214+
151215
@app.command(name="set-project")
152216
def set_project(project_id: str):
153217
"""Set current project."""

0 commit comments

Comments
 (0)