From d527646cbe0e82de73798cc200f80fe7c62e3af8 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Mon, 11 Apr 2022 15:16:34 -0400 Subject: [PATCH] pybind/mgr: add format arg to Responder's extra args To ensure that the Responder can make use of a user provided `--format=` parameter even if the programmer doesn't explicitly add one to the args of an endpoint function we set the `extra_args` attribute on our wrapper function so that CLICommand can later extract it. Signed-off-by: John Mulligan (cherry picked from commit efee0d7ebc5d990338eb6d256fe23717bafe128d) --- src/pybind/mgr/object_format.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/pybind/mgr/object_format.py b/src/pybind/mgr/object_format.py index fb89e9034ee9b..2df6584b90809 100644 --- a/src/pybind/mgr/object_format.py +++ b/src/pybind/mgr/object_format.py @@ -278,7 +278,11 @@ class Responder: A function that returns a Python object will have the object converted into a return value and formatted response body, based on the `format` argument - passed to the mgr. + passed to the mgr. When used from the ceph cli tool the `--format=[name]` + argument is mapped to a `format` keyword argument. The decorated function + may provide a `format` argument (type str). If the decorated function does + not provide a `format` argument itself, the Responder decorator will + implicitly add one to the MGR's "CLI arguments" handling stack. The Responder object is callable and is expected to be used as a decorator. """ @@ -344,4 +348,8 @@ class Responder: return e.format_response() return retval, body, "" + # set the extra args on our wrapper function. this will be consumed by + # the CLICommand decorator and added to the set of optional arguments + # on the ceph cli/api + setattr(_format_response, "extra_args", {"format": str}) return _format_response -- 2.39.5