Skip to content

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

Open
ben-kalmus wants to merge 3 commits into
feat/interactive-packagefrom
feat/compositions-interactive-mode
Open

feat(compositions): add interactive mode to compositions commands#252
ben-kalmus wants to merge 3 commits 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 437 complexity · 211 duplication

Metric Results
Complexity 437
Duplication 211

View in Codacy

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

@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
@ben-kalmus ben-kalmus force-pushed the feat/interactive-package branch from c17e3a6 to 9a22ae5 Compare June 19, 2026 16:12
@ben-kalmus ben-kalmus force-pushed the feat/compositions-interactive-mode branch from 25d7c61 to 09a8a59 Compare June 19, 2026 16:13
@ben-kalmus ben-kalmus force-pushed the feat/interactive-package branch from 9a22ae5 to d0c4a17 Compare July 6, 2026 11:31
@ben-kalmus ben-kalmus force-pushed the feat/compositions-interactive-mode branch from cc9c665 to 1c99234 Compare July 6, 2026 11:35

@LorrisSaintGenez LorrisSaintGenez left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Feel free to merge into #249 once you fix them

Comment thread pkg/cmd/compositions/search/search.go
Comment thread pkg/cmd/compositions/rules/upsert/upsert.go Outdated
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.
- search: reject a positional query or --hits-per-page/--page/--filters when
  --interactive is set, instead of silently ignoring them
- drop the redundant nil-Prompter fallback in upsert, rules upsert, search, and
  sorting-strategy (factory.New always sets it; Builder errors on nil anyway)
@ben-kalmus ben-kalmus force-pushed the feat/compositions-interactive-mode branch from 1c99234 to a8ec51f Compare July 7, 2026 16:35
@ben-kalmus ben-kalmus force-pushed the feat/interactive-package branch from 78d6c9b to a221553 Compare July 7, 2026 16:35
@ben-kalmus

Copy link
Copy Markdown
Contributor Author

Feel free to merge into #249 once you fix them

@LorrisSaintGenez I thought i'd merge in the interactive builder into main first, then rebase this branch on main and merge that after. Or do you prefer merging one squashed commit with both interactive + compositions ?

@LorrisSaintGenez

Copy link
Copy Markdown
Contributor

@ben-kalmus You can do that too yes!

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.

2 participants