Skip to content

feat(compositions): add interactive mode to compositions commands#252

Open
ben-kalmus wants to merge 1 commit into
feat/interactive-packagefrom
feat/compositions-interactive-mode
Open

feat(compositions): add interactive mode to compositions commands#252
ben-kalmus wants to merge 1 commit into
feat/interactive-packagefrom
feat/compositions-interactive-mode

Conversation

@ben-kalmus

@ben-kalmus ben-kalmus commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds an --interactive/-i flag to the compositions commands that build a request body, so users can construct the body through prompts instead of hand-writing JSON.

  • Covered commands:

    • compositions upsert (Composition),
    • compositions rules upsert (CompositionRule),
    • compositions search (search RequestBody).
  • Stacked on the interactive engine PR feat(interactive): add reflection-driven interactive prompt engine #249 (merge that first).

Demos

Upsert

compositions-upsert

Upsert Rule

compositions-rules-upsert-interactive

Search

compositions-search-interactive

Stacked PRs

Usage

# Build a composition interactively
algolia compositions upsert my-comp --interactive

# Build a composition rule interactively
algolia compositions rules upsert my-comp rule-1 --interactive

# Build a search request interactively (query becomes optional under -i)
algolia compositions search my-comp --interactive

# Still supported: from a file or stdin
algolia compositions upsert my-comp --file body.json
cat rule.json | algolia compositions rules upsert my-comp rule-1 --file -

Design notes

  • The Prompter is provided by cmdutil.Factory (defaulted to a survey-backed prompter in factory.New), so each command receives it as a dependency and tests inject a fake. No test-only seam on the command signatures.

  • For the write commands, --file and --interactive are mutually exclusive and exactly one is required. For search, --interactive makes the positional <query> optional (the request is built from prompts). --interactive always requires a TTY and errors otherwise.

  • Identifiers from positional args are pre-populated (composition objectID, rule objectID), so they are not prompted.

  • Non-interactive (--file / positional query) behavior is unchanged.

Changes

  • pkg/cmdutil/factory.go: add a Prompter field to Factory.
  • pkg/cmd/factory/default.go: default Prompter to a survey-backed prompter built from the IO streams.
  • pkg/cmd/compositions/upsert/upsert.go: --interactive/-i, flag validation, interactive build path.
  • pkg/cmd/compositions/rules/upsert/upsert.go: same for composition rules (CompositionRule).
  • pkg/cmd/compositions/search/search.go: --interactive/-i building the search RequestBody; query argument made optional under -i (RangeArgs(1,2)).
  • Test files for each command plus a group-level integration test (pkg/cmd/compositions/compositions_test.go).

Tests

  • Interactive happy paths for upsert (full PUT body via JSONEq at the command-group level), rules upsert, and search, all driven by a scripted prompter on the factory.
  • Guards per command: --file + --interactive conflict, and --interactive without a TTY.
  • Existing --file / positional-query behavior covered by the unchanged tests.

@ben-kalmus ben-kalmus changed the base branch from main to feat/interactive-package June 18, 2026 10:16
@codacy-production

codacy-production Bot commented Jun 18, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 18 duplication

Metric Results
Complexity 0
Duplication 18

View in Codacy

TIP This summary will be updated as you push new changes.

Inject a Prompter through cmdutil.Factory (defaulted to a survey-backed
prompter in factory.New) and add an --interactive/-i flag to the compositions
commands that build a request body:

- compositions upsert        -> Composition
- compositions rules upsert  -> CompositionRule
- compositions search        -> search RequestBody (query optional under -i)

Each builds the body with the interactive engine instead of requiring JSON;
--file and --interactive are mutually exclusive and interactive requires a TTY.
Adds a group-level integration test plus per-command interactive tests.
@ben-kalmus ben-kalmus force-pushed the feat/compositions-interactive-mode branch from 4f6cadc to 25d7c61 Compare June 18, 2026 10:38
@ben-kalmus ben-kalmus changed the title Feat/compositions interactive mode feat: add --interactive mode to compositions commands Jun 18, 2026
@ben-kalmus ben-kalmus changed the title feat: add --interactive mode to compositions commands feat(compositions): add interactive mode to compositions commands Jun 18, 2026
@ben-kalmus ben-kalmus marked this pull request as ready for review June 18, 2026 11:21
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.

1 participant