feat(cli): add profile switching, bulk-import with column mapping, and fix shell completions
Description
This PR introduces three major, high-impact improvements to the Moss CLI to enhance developer experience, streamline multi-project workflows, and fix a critical bug in the shell completions command.
1. π Fix Shell Completions Fall-through Bug
While running the CLI tests, I discovered that the command was failing with:
Shell completion is unavailable in this Typer installation.
Upon inspection of packages/moss-cli/src/moss_cli/commands/completions.py, I identified a fall-through bug in the exception handling block:
except Exception: # pragma: no cover
try:
from typer._completion_shared import get_completion_script # type: ignore
except Exception: # pragma: no cover - depends on Typer installation
output.print_error(
"Shell completion is unavailable in this Typer installation.",
json_mode,
)
raise typer.Exit(1)
output.print_error(
"Shell completion is unavailable in this Typer installation.",
json_mode,
)
raise typer.Exit(1)
Even when the inner import from typer._completion_shared succeeded, the code fell through to print the error and exit non-zero.
- Fix: Removed the duplicate error print/raise block at the end of the outer
exceptblock so that successful imports correctly proceed to script generation. - Result: All shell completion tests are now 100% green!
2. π Profile Switching Commands (Closes #176, Closes #126)
Added subcommands to make switching between named credential profiles seamless and explicit without manually editing configuration files or relying on environment variables:
moss profile use <profile-name>(ormoss profile set-default <profile-name>): Sets the active/default profile in the config.moss profile current: Displays the currently selected profile (taking into account CLI flags and env vars).
3. π₯ Bulk-Import with Column Mapping (Closes #379)
Added a powerful bulk-loading command to import documents from arbitrary CSV, JSON, or JSONL files without writing code:
moss doc import <index_name> -f <file_path>- Supports column mapping via
--id-column / -iand--text-column / -tto map arbitrary column/key names to document ID and text. - Automatically maps all other columns/keys to the document's
metadatadictionary (satisfying theDict[str, str]constraint ofDocumentInfoby converting values to strings and serializing complex objects/lists to JSON strings). - Supports explicit metadata filtering selection via
--metadata-columns / -mand toggling with--include-all-metadata / --no-include-all-metadata.
4. π§ͺ Comprehensive Test Coverage
Added robust unit and integration tests in tests/test_profiles.py covering:
set_active_profilesuccess and failure paths.moss profile use,set-default, andcurrentCLI commands.- CSV, JSON, and JSONL document parsers with arbitrary column mapping.
- End-to-end integration test of
moss doc importwith mocked API client responses.
All 42 CLI tests are now fully passing!