(self, lib, opts, args)
| 96 | return [cmd] |
| 97 | |
| 98 | def run(self, lib, opts, args): |
| 99 | # Gather the commands from Beets core and its plugins. |
| 100 | # Collect the album and track fields. |
| 101 | # If specified, also collect the values for these fields. |
| 102 | # Make a giant string of all the above, formatted in a way that |
| 103 | # allows Fish to do tab completion for the `beet` command. |
| 104 | |
| 105 | completion_file_path = os.path.expanduser(opts.output) |
| 106 | completion_dir = os.path.dirname(completion_file_path) |
| 107 | |
| 108 | if completion_dir != "": |
| 109 | os.makedirs(completion_dir, exist_ok=True) |
| 110 | |
| 111 | nobasicfields = opts.noFields # Do not complete for album/track fields |
| 112 | extravalues = opts.extravalues # e.g., Also complete artists names |
| 113 | beetcmds = sorted( |
| 114 | (commands.default_commands + plugins.commands()), |
| 115 | key=attrgetter("name"), |
| 116 | ) |
| 117 | fields = sorted(library.Album.all_keys() | library.Item.all_keys()) |
| 118 | # Collect commands, their aliases, and their help text |
| 119 | cmd_names_help = [] |
| 120 | for cmd in beetcmds: |
| 121 | names = list(cmd.aliases) |
| 122 | names.append(cmd.name) |
| 123 | for name in names: |
| 124 | cmd_names_help.append((name, cmd.help)) |
| 125 | # Concatenate the string |
| 126 | totstring = f"{HEAD}\n" |
| 127 | totstring += get_cmds_list([name[0] for name in cmd_names_help]) |
| 128 | totstring += "" if nobasicfields else get_standard_fields(fields) |
| 129 | totstring += get_extravalues(lib, extravalues) if extravalues else "" |
| 130 | totstring += "\n# ====== setup basic beet completion =====\n\n" |
| 131 | totstring += get_basic_beet_options() |
| 132 | totstring += "\n# ====== setup field completion for subcommands =====\n" |
| 133 | totstring += get_subcommands(cmd_names_help, nobasicfields, extravalues) |
| 134 | # Set up completion for all the command options |
| 135 | totstring += get_all_commands(beetcmds) |
| 136 | |
| 137 | with open(completion_file_path, "w") as fish_file: |
| 138 | fish_file.write(totstring) |
| 139 | |
| 140 | |
| 141 | def _escape(name): |
no test coverage detected