@@ -58,9 +58,21 @@ def tool_list(config: Config, verbose: int, github_token: str, version_check: bo
5858 help = "A version to install for the requested tool. "
5959 + "By default, the latest version is installed." ,
6060)
61- @click .argument ("tool" )
61+ @click .option (
62+ "--missing" ,
63+ is_flag = True ,
64+ default = False ,
65+ help = "Install the latest version for all currently unmanaged tools. "
66+ + "This flag and providing a tool name on the command line are mutually exclusive." ,
67+ )
68+ @click .argument ("tool" , required = False , default = "" )
6269def tool_install (
63- config : Config , verbose : int , tool : str , version : Optional [str ], github_token : str
70+ config : Config ,
71+ verbose : int ,
72+ tool : str ,
73+ version : Optional [str ],
74+ github_token : str ,
75+ missing : bool ,
6476):
6577 """Install one of the required tools in `$XDG_CACHE_DIR/commodore/tools`.
6678
@@ -73,10 +85,28 @@ def tool_install(
7385
7486 Optionally, the command accepts a tool version to install. The command
7587 accepts versions prefixed with "v" and unprefixed versions.
88+
89+ Alternatively, the command can install the latest version for all required
90+ tools which aren't managed by Commodore yet by passing flag --all. This flag
91+ is mutually exclusive with providing a tool name.
7692 """
7793 config .update_verbosity (verbose )
7894 config .github_token = github_token
79- tools .install_tool (config , tool , version )
95+
96+ if not tool and not missing or tool and missing :
97+ raise click .ClickException (
98+ "`commodore install tool` expects to be called with either a tool name or the `--missing` flag."
99+ )
100+ if missing and version :
101+ click .secho (
102+ "Flag `--version` has no effect when calling the command with `--missing`." ,
103+ fg = "yellow" ,
104+ )
105+
106+ if missing :
107+ tools .install_missing_tools (config )
108+ else :
109+ tools .install_tool (config , tool , version )
80110
81111
82112@tool_group .command (name = "upgrade" , short_help = "Upgrade external tools" )
@@ -90,9 +120,21 @@ def tool_install(
90120 help = "A version to upgrade (or downgrade) to for the requested tool. "
91121 + "By default, the tool is upgraded to the latest version." ,
92122)
93- @click .argument ("tool" )
123+ @click .option (
124+ "--all" ,
125+ is_flag = True ,
126+ default = False ,
127+ help = "Upgrade all currently managed tools to their latest versions. "
128+ + "This flag and providing a tool name on the command line are mutually exclusive." ,
129+ )
130+ @click .argument ("tool" , required = False , default = "" )
94131def tool_upgrade (
95- config : Config , verbose : int , tool : str , version : Optional [str ], github_token : str
132+ config : Config ,
133+ verbose : int ,
134+ tool : str ,
135+ version : Optional [str ],
136+ github_token : str ,
137+ all : bool ,
96138):
97139 """Upgrade (or downgrade) one of the required tools in `$XDG_CACHE_DIR/commodore/tools`.
98140
@@ -106,7 +148,24 @@ def tool_upgrade(
106148
107149 Optionally, the command accepts a tool version to upgrade (or downgrade) to.
108150 The command accepts versions prefixed with "v" and unprefixed versions.
151+
152+ Alternatively, the command can upgrade all managed tools to their latest
153+ versions by passing flag --all. This flag is mutually exclusive with
154+ providing a tool name.
109155 """
110156 config .update_verbosity (verbose )
111157 config .github_token = github_token
112- tools .upgrade_tool (config , tool , version )
158+
159+ if not tool and not all or tool and all :
160+ raise click .ClickException (
161+ "`commodore upgrade tool` expects to be called with either a tool name or the `--all` flag."
162+ )
163+ if all and version :
164+ click .secho (
165+ "Flag `--version` has no effect when calling the command with `--all`." ,
166+ fg = "yellow" ,
167+ )
168+ if all :
169+ tools .upgrade_all_tools (config )
170+ else :
171+ tools .upgrade_tool (config , tool , version )
0 commit comments