@@ -63,9 +63,21 @@ def tool_list(config: Config, verbose: int, github_token: str, version_check: bo
6363 help = "A version to install for the requested tool. "
6464 + "By default, the latest version is installed." ,
6565)
66- @click .argument ("tool" )
66+ @click .option (
67+ "--missing" ,
68+ is_flag = True ,
69+ default = False ,
70+ help = "Install the latest version for all currently unmanaged tools. "
71+ + "This flag and providing a tool name on the command line are mutually exclusive." ,
72+ )
73+ @click .argument ("tool" , required = False , default = "" )
6774def tool_install (
68- config : Config , verbose : int , tool : str , version : Optional [str ], github_token : str
75+ config : Config ,
76+ verbose : int ,
77+ tool : str ,
78+ version : Optional [str ],
79+ github_token : str ,
80+ missing : bool ,
6981):
7082 """Install one of the required tools in `$XDG_CACHE_DIR/commodore/tools`.
7183
@@ -78,10 +90,28 @@ def tool_install(
7890
7991 Optionally, the command accepts a tool version to install. The command
8092 accepts versions prefixed with "v" and unprefixed versions.
93+
94+ Alternatively, the command can install the latest version for all required
95+ tools which aren't managed by Commodore yet by passing flag `--missing`.
96+ This flag is mutually exclusive with providing a tool name.
8197 """
8298 config .update_verbosity (verbose )
8399 config .github_token = github_token
84- tools .install_tool (config , tool , version )
100+
101+ if not tool and not missing or tool and missing :
102+ raise click .ClickException (
103+ "`commodore tool install` expects to be called with either a tool name or the `--missing` flag."
104+ )
105+ if missing and version :
106+ click .secho (
107+ "Flag `--version` has no effect when calling the command with `--missing`." ,
108+ fg = "yellow" ,
109+ )
110+
111+ if missing :
112+ tools .install_missing_tools (config )
113+ else :
114+ tools .install_tool (config , tool , version )
85115
86116
87117@tool_group .command (name = "upgrade" , short_help = "Upgrade external tools" )
@@ -95,9 +125,21 @@ def tool_install(
95125 help = "A version to upgrade (or downgrade) to for the requested tool. "
96126 + "By default, the tool is upgraded to the latest version." ,
97127)
98- @click .argument ("tool" )
128+ @click .option (
129+ "--all" ,
130+ is_flag = True ,
131+ default = False ,
132+ help = "Upgrade all currently managed tools to their latest versions. "
133+ + "This flag and providing a tool name on the command line are mutually exclusive." ,
134+ )
135+ @click .argument ("tool" , required = False , default = "" )
99136def tool_upgrade (
100- config : Config , verbose : int , tool : str , version : Optional [str ], github_token : str
137+ config : Config ,
138+ verbose : int ,
139+ tool : str ,
140+ version : Optional [str ],
141+ github_token : str ,
142+ all : bool ,
101143):
102144 """Upgrade (or downgrade) one of the required tools in `$XDG_CACHE_DIR/commodore/tools`.
103145
@@ -111,7 +153,24 @@ def tool_upgrade(
111153
112154 Optionally, the command accepts a tool version to upgrade (or downgrade) to.
113155 The command accepts versions prefixed with "v" and unprefixed versions.
156+
157+ Alternatively, the command can upgrade all managed tools to their latest
158+ versions by passing flag `--all`. This flag is mutually exclusive with
159+ providing a tool name.
114160 """
115161 config .update_verbosity (verbose )
116162 config .github_token = github_token
117- tools .upgrade_tool (config , tool , version )
163+
164+ if not tool and not all or tool and all :
165+ raise click .ClickException (
166+ "`commodore tool upgrade` expects to be called with either a tool name or the `--all` flag."
167+ )
168+ if all and version :
169+ click .secho (
170+ "Flag `--version` has no effect when calling the command with `--all`." ,
171+ fg = "yellow" ,
172+ )
173+ if all :
174+ tools .upgrade_all_tools (config )
175+ else :
176+ tools .upgrade_tool (config , tool , version )
0 commit comments