feat(compositions): add interactive mode to compositions commands#252
Open
ben-kalmus wants to merge 1 commit into
Open
feat(compositions): add interactive mode to compositions commands#252ben-kalmus wants to merge 1 commit into
ben-kalmus wants to merge 1 commit into
Conversation
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
| Duplication | 18 |
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.
4f6cadc to
25d7c61
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an
--interactive/-iflag to thecompositionscommands 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
Upsert Rule
Search
Stacked PRs
feat(interactive): add reflection-driven interactive prompt engine #249 <- this PR
feat(compositions): add interactive mode to compositions commands #252
Usage
Design notes
The
Prompteris provided bycmdutil.Factory(defaulted to a survey-backed prompter infactory.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,
--fileand--interactiveare mutually exclusive and exactly one is required. Forsearch,--interactivemakes the positional<query>optional (the request is built from prompts).--interactivealways 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 aPrompterfield toFactory.pkg/cmd/factory/default.go: defaultPrompterto 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/-ibuilding the searchRequestBody; query argument made optional under-i(RangeArgs(1,2)).pkg/cmd/compositions/compositions_test.go).Tests
JSONEqat the command-group level), rules upsert, and search, all driven by a scripted prompter on the factory.--file+--interactiveconflict, and--interactivewithout a TTY.--file/ positional-query behavior covered by the unchanged tests.