From 2730784a5bcdca0f8f5f05fb11142abaec52f657 Mon Sep 17 00:00:00 2001 From: Jason Yundt Date: Wed, 6 Sep 2023 17:50:53 -0400 Subject: [PATCH 1/2] =?UTF-8?q?Allow=20parsers=20that=20don=E2=80=99t=20ha?= =?UTF-8?q?ndle=20commands=20yet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Parsers serve two purposes: 1. They determine whether or not a command executes its arguments. 2. They determine which parts of a command’s arguments are other commands that get executed. Before this change, parsers would have to do both, or else you would get an AttributeError. Now, you can create a partial parser that can confirm that a specific invocation doesn’t run any of its arguments but can’t handle invocations that do run their arguments. Specifically, this change is in preparation for adding a parser for flatpak. flatpak has 43 built-in subcommands, some of which are able to execute their arguments. I don’t want to bother adding a parser that supports all 43 of those. I want to add a parser that supports a single subcommand, and that subcommand can’t run its arguments. --- resholve | 3 +++ 1 file changed, 3 insertions(+) diff --git a/resholve b/resholve index 57adce4..7a9ed2c 100755 --- a/resholve +++ b/resholve @@ -3837,6 +3837,9 @@ class RecordCommandlike(object): return True def handle_external_generic(self, parsed, invocation): + if not hasattr(parsed, "commands"): + return True + # TODO: shimming shells in here may be a bigger crime than # duplicating the logic in two functions would be? shell = invocation.firstword in INVOKABLE_SHELLS From 2b0b5fd69d749550adf971a1fd198dcebb5cf524 Mon Sep 17 00:00:00 2001 From: Jason Yundt Date: Wed, 6 Sep 2023 17:22:50 -0400 Subject: [PATCH 2/2] Add parser for flatpak and flatpak update MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This parser doesn’t cover all of flatpak’s subcommands because I don’t use all of flatpak’s subcommands in my own scripts. I created this script in order to help me test out this change: --- resholve | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/resholve b/resholve index 7a9ed2c..83b7a3a 100755 --- a/resholve +++ b/resholve @@ -2395,6 +2395,68 @@ class ExternalCommandParsers(object): return (generic,) + @staticmethod + def _flatpak(): + """ + Based on Flatpak v1.14.4. + """ + generic = CommandParser("flatpak") + + # flatpak --help + generic.add_argument( + "-h", "--help", + "--version", + "--default-arch", + "--supported-arches", + "--gl-drivers", + "--installations", + "--print-updated-env", + "--print-system-only", + "-v", "--verbose", + "--ostree-verbose", + action="store_true" + ) + subparsers = generic.add_subparsers() + # flatpak update --help + update = subparsers.add_parser("update") + update.add_argument( + "-h", "--help", + "-u", "--user", + "--system", + action="store_true" + ) + update.add_argument( + "--installation", + "--arch", + "--commit", + nargs=1 + ) + update.add_argument( + "--force-remove", + "--no-pull", + "--no-deploy", + "--no-related", + "--no-deps", + "--no-static-deltas", + "--runtime", + "--app", + "--appstream", + action="store_true" + ) + update.add_argument("--subpath", nargs=1) + update.add_argument( + "-y", "--assumeyes", + "--noninteractive", + ) + update.add_argument("--sideload-repo", nargs=1) + update.add_argument( + "-v", "--verbose", + "--ostree-verbose", + action="store_true" + ) + + return (generic,) + def generate_builtin_command_parser(cmdname): cmdname = "_" + cmdname