@@ -11,24 +11,22 @@ import (
1111 "runtime"
1212)
1313
14- func latestDockerImage () {
14+ type commandRunner func (name string , args ... string ) * exec.Cmd
15+
16+ func latestDockerImage (run commandRunner ) {
1517 var cmd * exec.Cmd
1618
1719 if runtime .GOOS == "windows" {
18- // Windows PowerShell equivalent
19- cmd = exec .Command ("powershell" , "-Command" , `
20- $tags = Invoke-RestMethod -Uri "https://hub.docker.com/v2/repositories/digitalghostdev/poke-cli/tags/?page_size=1";
21- $tags.results[0].name
22- ` )
20+ cmd = run ("powershell" , "-Command" , `
21+ $tags = Invoke-RestMethod -Uri "https://hub.docker.com/v2/repositories/digitalghostdev/poke-cli/tags/?page_size=1";
22+ $tags.results[0].name
23+ ` )
2324 } else {
24- // Check if curl is available
2525 _ , err := exec .LookPath ("curl" )
2626 if err == nil {
27- // Use curl if available
28- cmd = exec .Command ("sh" , "-c" , `curl -s https://hub.docker.com/v2/repositories/digitalghostdev/poke-cli/tags/?page_size=1 | grep -o '"name":"[^"]*"' | cut -d '"' -f 4` )
27+ cmd = run ("sh" , "-c" , `curl -s https://hub.docker.com/v2/repositories/digitalghostdev/poke-cli/tags/?page_size=1 | grep -o '"name":"[^"]*"' | cut -d '"' -f 4` )
2928 } else {
30- // Use wget as a fallback
31- cmd = exec .Command ("sh" , "-c" , `wget -qO- https://hub.docker.com/v2/repositories/digitalghostdev/poke-cli/tags/?page_size=1 | grep -o '"name":"[^"]*"' | cut -d '"' -f 4` )
29+ cmd = run ("sh" , "-c" , `wget -qO- https://hub.docker.com/v2/repositories/digitalghostdev/poke-cli/tags/?page_size=1 | grep -o '"name":"[^"]*"' | cut -d '"' -f 4` )
3230 }
3331 }
3432
@@ -90,6 +88,6 @@ func latestRelease(githubAPIURL string) {
9088
9189func LatestFlag () {
9290 // cmd := exec.Command("git", "describe", "--tags", "--abbrev=0")
93- latestDockerImage ()
91+ latestDockerImage (exec . Command )
9492 latestRelease ("https://api.github.com/repos/digitalghost-dev/poke-cli/releases/latest" )
9593}
0 commit comments