]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
tools: ynl: use operation names from spec on the CLI
authorJakub Kicinski <kuba@kernel.org>
Tue, 31 Jan 2023 02:33:49 +0000 (18:33 -0800)
committerJakub Kicinski <kuba@kernel.org>
Wed, 1 Feb 2023 04:36:03 +0000 (20:36 -0800)
When I wrote the first version of the Python code I was quite
excited that we can generate class methods directly from the
spec. Unfortunately we need to use valid identifiers for method
names (specifically no dashes are allowed). Don't reuse those
names on the CLI, it's much more natural to use the operation
names exactly as listed in the spec.

Instead of:
  ./cli --do rings_get
use:
  ./cli --do rings-get

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
tools/net/ynl/cli.py
tools/net/ynl/lib/ynl.py

index 5c4eb5a6851482b81d5806513d0ca17f3babc9cd..05d1f4069ce12e8b5589de3cdf63d7c4fdccf64d 100755 (executable)
@@ -32,10 +32,11 @@ def main():
     if args.sleep:
         time.sleep(args.sleep)
 
-    if args.do or args.dump:
-        method = getattr(ynl, args.do if args.do else args.dump)
-
-        reply = method(attrs, dump=bool(args.dump))
+    if args.do:
+        reply = ynl.do(args.do, attrs)
+        pprint.PrettyPrinter().pprint(reply)
+    if args.dump:
+        reply = ynl.dump(args.dump, attrs)
         pprint.PrettyPrinter().pprint(reply)
 
     if args.ntf:
index 2ff3e6dbdbf60f3752306a621085fea70a8b1ba5..1c7411ee04dc875c7924fa83bba784239b62ff97 100644 (file)
@@ -520,3 +520,9 @@ class YnlFamily(SpecFamily):
         if not dump and len(rsp) == 1:
             return rsp[0]
         return rsp
+
+    def do(self, method, vals):
+        return self._op(method, vals)
+
+    def dump(self, method, vals):
+        return self._op(method, vals, dump=True)