You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In `click`, every subcommand is accompanied by a `click.Context`, and objects can be attached to them.
55
-
In this CLI we attach a [`PulpCLIContext`][pulp_cli.generic.PulpCLIContext] to the main command, which inherits from `pulp-glue`'s [`PulpContext`][pulp_glue.common.context.PulpContext].
55
+
In this CLI we attach a [`PulpCLIContext`][pulp_cli.generic.PulpCLIContext] to the main command,
56
+
which inherits from `pulp-glue`'s [`PulpContext`][pulp_glue.common.context.PulpContext].
56
57
This context handles the communication to the pulp server through its `api` property.
57
58
58
-
Further we encourage the handling of communication with certain endpoints by subclassing the [`PulpEntityContext`][pulp_glue.common.context.PulpEntityContext] or some of the resource-specific children, such as [PulpRepositoryContext][pulp_glue.common.context.PulpRepositoryContext].
59
+
Further we encourage the handling of communication with certain endpoints by subclassing the [`PulpEntityContext`][pulp_glue.common.context.PulpEntityContext]
60
+
or some of the resource-specific children, such as [`PulpRepositoryContext`][pulp_glue.common.context.PulpRepositoryContext].
59
61
Some examples of this can be found under `pulp_glue/{plugin-name}/context.py`.
60
62
61
63
By attaching them to the contexts of certain command groups, they are accessible to commands via the `pass_entity_context` decorator.
@@ -65,41 +67,58 @@ Those entity contexts should provide a common interface to the layer of `click`
# At this point, the lookup option has already selected an entity.
106
+
entity_ctx.frobnicate()
90
107
```
91
108
92
109
To add options to these subcommands, pass a list of [`PulpOption`][pulp_cli.generic.PulpOption] objects to the `decorators` argument.
93
110
Preferably these are created using the [`pulp_option`][pulp_cli.generic.pulp_option] factory.
111
+
More specific factories for resource handling are [`resource_option`][pulp_cli.generic.resource_option] and [`resource_lookup_option`][pulp_cli.generic.resource_lookup_option].
94
112
113
+
Another example is the `list-command` that allows filtering (based on the server's capabilities) by adding named options:
To declare version restrictions on *options*, the [`preprocess_entity`][pulp_glue.common.context.PulpEntityContext.preprocess_entity] method can be used to check if a given option is present in the request body and conditionally apply the requirements to the context.
0 commit comments