refactor: unify image download into a single DownloadImageCmd
DownloadImageCmd and DownloadWireguardImageCmd were identical except for the image URL. Collapse them into one DownloadImageCmd that takes the image as a parameter, passing imageName/wireguardImageName at the call sites. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+3
-27
@@ -43,12 +43,10 @@ func TickCmd() tea.Cmd {
|
||||
})
|
||||
}
|
||||
|
||||
func DownloadImageCmd(username, password string) tea.Cmd {
|
||||
func DownloadImageCmd(image, username, password string) tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
url := imageName
|
||||
|
||||
loginOut, err := exec.Command(
|
||||
"docker", "login", url,
|
||||
"docker", "login", image,
|
||||
"-u", username,
|
||||
"-p", password,
|
||||
).CombinedOutput()
|
||||
@@ -60,29 +58,7 @@ func DownloadImageCmd(username, password string) tea.Cmd {
|
||||
}
|
||||
}
|
||||
|
||||
message, err := PullImage(url)
|
||||
return ImageDownloadFinishedMsg{Message: message, Err: err}
|
||||
}
|
||||
}
|
||||
|
||||
func DownloadWireguardImageCmd(username, password string) tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
url := wireguardImageName
|
||||
|
||||
loginOut, err := exec.Command(
|
||||
"docker", "login", url,
|
||||
"-u", username,
|
||||
"-p", password,
|
||||
).CombinedOutput()
|
||||
|
||||
if err != nil {
|
||||
return ImageDownloadFinishedMsg{
|
||||
Message: string(loginOut),
|
||||
Err: fmt.Errorf("falha no login: %w", err),
|
||||
}
|
||||
}
|
||||
|
||||
message, err := PullImage(url)
|
||||
message, err := PullImage(image)
|
||||
return ImageDownloadFinishedMsg{Message: message, Err: err}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user