Skip to content

Show usage hint when shell starts disconnected (#81)#82

Open
mkrueger wants to merge 3 commits into
mainfrom
dev/mkrueger/issue81
Open

Show usage hint when shell starts disconnected (#81)#82
mkrueger wants to merge 3 commits into
mainfrom
dev/mkrueger/issue81

Conversation

@mkrueger
Copy link
Copy Markdown
Contributor

@mkrueger mkrueger commented May 11, 2026

Refs #81.
image

A first-time user launching cosmosdbshell lands at the prompt with no indication that authentication is required or how to perform it. The connect command works, but its existence isn't surfaced anywhere by the welcome banner.

This PR adds two small, surgical hints — no command-surface changes:

1. Disconnected startup hint

After the existing Cosmos DB shell ready. banner, when the shell starts in DisconnectedState, print a one-line yellow hint pointing at connect/help connect.

2. Better connect with no args while disconnected

When a user runs connect without arguments while not connected, follow the existing Not connected to any Cosmos DB account. line with a small usage block listing the connect examples taken straight from the command's [CosmosExample] metadata, plus a pointer to help connect. Reusing CommandFactory.ExamplesWithDescriptions keeps a single source of truth shared with the help system, so adding new credential flavors automatically updates this hint.

What it looks like

Before:

Cosmos DB shell ready.
> connect
Not connected to any Cosmos DB account.

After:

Cosmos DB shell ready.
Not connected. Run 'connect <endpoint>' to authenticate, or 'help connect' for more options.
> connect
Not connected to any Cosmos DB account.
Use 'connect <endpoint>' to authenticate. Common forms:
  connect "AccountEndpoint=https://myaccount.documents.azure.com:443/;AccountKey=mykey;"
    Connect using connection string with account key
  connect https://localhost:8081
    Connect to the local Cosmos DB Emulator (uses well-known key and gateway mode)
  connect https://myaccount.documents.azure.com:443/ -hint=user@contoso.com
    Connect using Entra ID authentication with login hint
  connect https://myaccount.documents.azure.com:443/ -tenant=<tenant-id> -mode=gateway
    Connect using Entra ID with gateway connection mode
  connect https://myaccount.documents.azure.com:443/ -managed-identity=<client-id>
    Connect using a user-assigned managed identity
Run 'help connect' for the full list of options.

Tests

Three new tests under ConnectCommandTests:

  • The new ftl strings (shell-not_connected_hint, command-connect-not_connected-usage-header, command-connect-not_connected-usage-footer) resolve to non-empty values — guards against typos in the localization references.
  • The connect command exposes example variants beyond the bare connect no-arg form so the hint helper has something to print.
  • The hint helper runs against a fresh ShellInterpreter without throwing.

(Local dotnet test was blocked by the VS Code LSP integration holding the shell binary; full suite verified once locally before that, and CI will re-run on the PR.)

Out of scope (worth a separate issue/PR)

  • Auto-connect flow on launch (would require an interactive prompt — bigger change to the shell startup contract).
  • Filing a docs PR against MicrosoftDocs/azure-docs to fix the "prompts you for authentication" line on Microsoft Learn.

…n with no args

Issue #81: a first-time user launching `cosmosdbshell` lands at the prompt
with no indication that authentication is required or how to perform it.
The legacy MS Learn doc says "it prompts you for authentication" but in
fact it does not — the user has to type `connect <endpoint>`, which is
not discoverable from the welcome banner.

Two surgical changes:

1. ShellInterpreter.RunAsync now prints a one-line yellow hint after the
   ready banner when the shell starts in DisconnectedState, telling the
   user to run `connect <endpoint>` (or `help connect`).

2. ConnectCommand.PrintConnectionInfoAsync now follows the existing
   "Not connected" line with a small usage block listing the connect
   examples taken from the command's CosmosExample metadata, plus a
   pointer to `help connect` for the full option list. Reusing
   ExamplesWithDescriptions keeps a single source of truth shared with
   the help system.

Adds three tests under ConnectCommandTests:

- The new ftl strings resolve to non-empty values.
- The connect command exposes example variants beyond the bare `connect`
  no-arg form so the hint helper has something to print.
- The hint helper runs against a fresh ShellInterpreter without throwing.

No command-surface changes; file-redirected and MCP output are unaffected
since the hint is written via AnsiConsole only when stdin is interactive.
@mkrueger mkrueger requested review from a team and Copilot May 11, 2026 11:36
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves first-run discoverability for authentication in the Cosmos DB Shell by adding user-facing hints when the shell starts disconnected and when connect is run with no arguments while disconnected (refs #81).

Changes:

  • Adds a yellow “not connected” hint on startup when the shell begins in DisconnectedState.
  • Enhances connect (no args, disconnected) to print a short usage block populated from the command’s [CosmosExample] metadata.
  • Adds tests to guard localization keys and ensure the new hint helper has examples and runs without throwing.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
CosmosDBShell/lang/en.ftl Adds new localized strings for the disconnected startup hint and connect usage header/footer.
CosmosDBShell/Azure.Data.Cosmos.Shell.Core/ShellInterpreter.cs Prints a startup hint when the shell launches in DisconnectedState.
CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/ConnectCommand.cs Adds PrintConnectUsageHint and invokes it when connect is run while disconnected.
CosmosDBShell.Tests/CommandTests/ConnectCommandTests.cs Adds tests for the new localization keys and a smoke test for the hint helper.

Comment thread CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/ConnectCommand.cs Outdated
Comment thread CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/ConnectCommand.cs
mkrueger added 2 commits May 11, 2026 13:46
The localized strings were passed directly to AnsiConsole.MarkupLine,
so a future translation containing '[' or ']' would be parsed as
Spectre markup. The example/description lines in the same helper
already use Markup.Escape; apply the same to the header and footer for
consistency. Addresses Copilot review feedback on PR #82.
Copilot AI review requested due to automatic review settings May 12, 2026 08:50
@mkrueger
Copy link
Copy Markdown
Contributor Author

mkrueger commented May 12, 2026

Changed output a bit:

image

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment thread CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/ConnectCommand.cs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants