clustershell icon indicating copy to clipboard operation
clustershell copied to clipboard

completion: handle , in node list

Open martinetd opened this issue 9 months ago • 0 comments

Split when multiple words are given to properly find matching nodes or groups:

  • get last partial nodeset
  • complete as if that was the current argument
  • then re-add the prefix for compword to match

==========

This is a bit too ugly for my taste so I tried doing the handling in cluset --complete, something like this is a start:

+        # --completion "$cur" (optional groups to complete)
+        if len(args) < 1:
+            return
+        cur_arg = args[0]
+        # try to get the last "word" from 'cur', for union/intersection:
+        # remove anything that doesn't contain a [, or contain both [ and ]
+        match = re.match(r'([^,[]*(\[[^]]*])?[,&])*(.*)', cur_arg)
+        if match:
+            cur = match.group(3)
+            prefix = cur_arg.removesuffix(cur)
+        else:
+            cur = cur_arg
+            prefix = ''

but even if we have this, it's printing completion suggestions through regular list and expand commands so we cannot really pre-match/add prefix as I would have liked to do, so here we are :/

Happy to say 1.9.3 gets completion only on first word, and we can work this through later if someone feels the need to... When using node names directly with different prefixes it is rather handy (e.g. clush -w foo1,bar3,moo4) but I don't think that's a major usecase.

martinetd avatar Jan 24 '25 12:01 martinetd