From: John Mulligan Date: Mon, 11 Apr 2022 19:16:34 +0000 (-0400) Subject: pybind/mgr: add format arg to Responder's extra args X-Git-Tag: v18.0.0~841^2~6 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=efee0d7ebc5d990338eb6d256fe23717bafe128d;p=ceph.git 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 --- diff --git a/src/pybind/mgr/object_format.py b/src/pybind/mgr/object_format.py index fb89e9034ee9..2df6584b9080 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