feat(endpoints): Values by option and optional extended value metadata#293
Open
ketiltrout wants to merge 1 commit into
Open
feat(endpoints): Values by option and optional extended value metadata#293ketiltrout wants to merge 1 commit into
ketiltrout wants to merge 1 commit into
Conversation
There are two related changes here: Endpoint values specified by option, not argument ------------------------------------------------- This changes the default way of specifying endpoint data to use (required) --options, instead of positional arguments on the command line. In the past, endpoint values in the client were read directly from endpoint files on the local system, so ensuring they kept a fixed order was easy. But now the values dict is forced through both YAML and JSON codecs and we can't guarantee that the dict keys retain their order. The side-effect of that, is there's no guarantee of which order the corresponding arguments ended up on the command line. So, to get around that, required --options are used to make the ordering on the command-line unimportant. Extended "values" metadata format in endpoint definitions --------------------------------------------------------- To allow more flexibility on how the coco CLI is built for an endpoint, the endpoint definition is extended to allow additional optional metadata for endpoint "values". This adds an alternate format for defining "values". Instead of the dict-of-types specification, a list-of-dicts can be used for "values" instead. In the list-of-dicts, each dict represents a single value. Each of these dicts is required to contain a "name" and a "type" (which recover the data in the old dict-of-types specification). There are additional, optional keys allowed in the dict which can be used to specify additional metadata, which is used by the client when building the CLI for this endpoint: * "params": string or list of strings. can be used to set the --option names used for the value. (For bools, this can be called "on-flags" instead, to match the next key.) * "off-flags": string or list of strings. For bool-types only, sets the names of the false-valued option flags. * "help": string. The help string to display * "option": boolean. Whether or not to use an --option or an argument for this parameter. Defaults to True * "meta": string. The metavar to use in help strings. The original dict-of-types specification is still supported. Additionally, for lists, the element type can also be specified: "list[int]". None of this extra data is used in the daemon. It's all extra metadata for the client. For backwards compatibility, this includes the item type specified for lists: the daemon does not validate the type of list items passed to it via JSON.
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.
There are two related changes here, which I though were low-priority, but I've realised the ordering of endpoint values in the client isn't fixed anymore, so this should sort that out:
Endpoint values specified by option, not argument
This changes the default way of specifying endpoint data to use (required) --options, instead of positional arguments on the command line.
In the past, endpoint values in the client were read directly from endpoint files on the local system, so ensuring they kept a fixed order was easy. But now the values dict is forced through both YAML and JSON codecs and we can't guarantee that the dict keys retain their order. The side-effect of that, is there's no guarantee of which order the corresponding arguments ended up on the command line.
So, to get around that, required --options are used to make the ordering on the command-line unimportant.
Extended "values" metadata format in endpoint definitions ---------------------------------------------------------
To allow more flexibility on how the coco CLI is built for an endpoint, the endpoint definition is extended to allow additional optional metadata for endpoint "values". This adds an alternate format for defining "values". Instead of the dict-of-types specification, a list-of-dicts can be used for "values" instead.
In the list-of-dicts, each dict represents a single value. Each of these dicts is required to contain a "name" and a "type" (which recover the data in the old dict-of-types specification). There are additional, optional keys allowed in the dict which can be used to specify additional metadata, which is used by the client when building the CLI for this endpoint:
The original dict-of-types specification is still supported.
Additionally, for lists, the element type can also be specified: "list[int]".
None of this extra data is used in the daemon. It's all extra metadata for the client. For backwards compatibility, this includes the item type specified for lists: the daemon does not validate the type of list items passed to it via JSON.