feat(cli): support pattern generation options passed on command line#2291
feat(cli): support pattern generation options passed on command line#2291markscott-ms wants to merge 3 commits intofinos:mainfrom
Conversation
jpgough-ms
left a comment
There was a problem hiding this comment.
I'm cool with the code for taking in a JSON file, but I do wonder if a better way for the CLI input would be to:
File Based
calm generate -p sample.pattern.json --option-choices file.json
Pairs of options and choices
calm generate -p sample.pattern.json --option http-or-https --choice https
cc/ @willosborne
Agree on the providing unique-id+choice, don't like how the syntax would look (and not sure if Commander can cope) with multiple options+choices. |
|
@markscott-ms it looks like the way to do this is... inline json. Seems a bit nasty, but maybe that's just the way it is |
|
Agreed that it would be nice to specify the answers inline without needing a separate file. I think @jpgough-ms suggestion of using commander arguments for this is probably quite difficult given the annotation-based way that commander parses these things but i think we can get something almost as nice with commander's built in features. I wonder if we could get something more like the way Kubectl lets you specify e.g. labels:
Working spike of that: This works fine because we don't use arguments, only options. so there's no issue with knowing when the options list ends and the arguments begin (normally this would need Another thought is that is all-or-nothing, you can either have it load answers for every question or ask every question. |
Description
Resolves #1951 opened by @niamhg-ms
This pull request adds support for providing pre-defined option choices to the CLI's
generatecommand, allowing users to skip interactive prompts by specifying choices via a JSON array or file. It also includes robust tests and error handling for this new feature.New CLI feature: Pre-defined option choices
--option-choicesflag to thegeneratecommand, allowing users to provide option choices as a JSON array of descriptions or as a path to a JSON file. When this flag is used, the CLI skips interactive prompts and uses the provided choices. [1] [2] [3]Implementation and logic
loadChoicesFromInputfunction ingenerate-options.tsto parse and validate pre-defined choices, ensuring they match valid options in the pattern and providing clear error messages for invalid input. [1] [2]Testing
loadChoicesFromInput, covering scenarios for inline JSON, JSON files, empty arrays, invalid choices, non-array input, and malformed JSON. [1] [2] [3]--option-choicescorrectly skips interactive prompts and uses the specified choices.Type of Change
Affected Components
cli/)calm/)calm-ai/)calm-hub/)calm-hub-ui/)calm-server/)calm-widgets/)docs/)shared/)calm-plugins/vscode/)Commit Message Format ✅
Testing
Checklist