From be9bcaeb92b5a83a1c691545df0eeedb2fe2dbf9 Mon Sep 17 00:00:00 2001 From: Reginald Alfret Date: Thu, 24 Sep 2026 22:18:55 +0530 Subject: [PATCH] Fix Fish completion for Fire(fn) Add command name to commands_set in _FishScript so that top-level function CLI completion registers completion directives for the command's flags. Analogous to #336 which fixed the same issue for Bash completion. Fixes #418 --- fire/completion.py | 6 +++++- fire/completion_test.py | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/fire/completion.py b/fire/completion.py index 1597d464..d191c097 100644 --- a/fire/completion.py +++ b/fire/completion.py @@ -259,7 +259,11 @@ def _FishScript(name, commands, default_options=None): "__option_entered_check --{option}' -l {option}\n") prev_global_check = ' and __is_prev_global;' - for command in set(subcommands_map.keys()).union(set(options_map.keys())): + commands_set = set() + commands_set.add(name) + commands_set = commands_set.union(set(subcommands_map.keys())) + commands_set = commands_set.union(set(options_map.keys())) + for command in commands_set: for subcommand in subcommands_map[command]: fish_source += subcommand_template.format( name=name, diff --git a/fire/completion_test.py b/fire/completion_test.py index c0d5d24f..34357f1a 100644 --- a/fire/completion_test.py +++ b/fire/completion_test.py @@ -134,6 +134,9 @@ def testDeepDictFishScript(self): def testFnFishScript(self): script = completion.Script('identity', tc.identity, shell='fish') + self.assertIn( + "complete -c identity -n '__fish_using_command identity;", script + ) self.assertIn('arg1', script) self.assertIn('arg2', script) self.assertIn('arg3', script)