kislyuk / argcomplete

Python and tab completion, better together.
https://kislyuk.github.io/argcomplete/
Apache License 2.0
1.39k stars 129 forks source link

Unable to get completion to work for NetExec #468

Closed Adamkadaban closed 6 months ago

Adamkadaban commented 6 months ago

I haven't been able to get this working for https://github.com/Pennyw0rth/NetExec

This is what the default output is of running without arguments: image

Syntax is nxc <protocol> <subargs>

Diff File:

diff --git a/nxc/cli.py b/nxc/cli.py
index 29fd91f8..c815017e 100755
--- a/nxc/cli.py
+++ b/nxc/cli.py
@@ -1,4 +1,5 @@
 import argparse
+import argcomplete
 import sys
 from argparse import RawTextHelpFormatter
 from nxc.loaders.protocolloader import ProtocolLoader
@@ -85,6 +86,7 @@ def gen_cli_args():
         parser.print_help()
         sys.exit(1)

+    argcomplete.autocomplete(parser)
     args = parser.parse_args()

     if args.version:
diff --git a/pyproject.toml b/pyproject.toml
index ef0f03bd..4ff77a1b 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -65,6 +65,7 @@ resource = "^0.2.1"
 oscrypto = { git = "https://github.com/Pennyw0rth/oscrypto" } # Pypi version currently broken, see: https://github.com/wbond/oscrypto/issues/78 (as of 9/23)
 pyreadline = "^2.1" # for the build - impacket imports its hidden from the builder so an error occurs
 ruff = "=0.0.292"
+argcomplete = "3.2.1"

 [tool.poetry.group.dev.dependencies]
 flake8 = "*"
@@ -123,4 +124,4 @@ target-version = "py37"
 [tool.ruff.flake8-quotes]
 docstring-quotes = "double"
 inline-quotes = "double"
-multiline-quotes = "double"
\ No newline at end of file
+multiline-quotes = "double"

I did eval "$(register-python-argcomplete nxc)" and eval "$(register-python-argcomplete netexec)" separately to see if it was an issue with naming.

When I export _ARC_DEBUG, it seems to run the program twice but doesn't parse any of the options.

I think this may be because of the subcategories for the tool (eg. nxc smb and nxc ssh). Is there a way to set up custom parsing for this?

Thanks

evanunderscore commented 6 months ago

At a glance I would guess this is your problem:

https://github.com/Pennyw0rth/NetExec/blob/ef4f2df92cc553274a09c38fead0030d5018481e/nxc/cli.py#L84-L86

We don't actually invoke your program with arguments, so you'll quit before generating completions. If moving argcomplete.autocomplete(parser) above this doesn't fix your problem, please show the output of attempted tab completion with _ARC_DEBUG=1.

Adamkadaban commented 6 months ago

Oh wow, that was a simple solution.

Thanks for the help! @evanunderscore