Skip to content

Instantly share code, notes, and snippets.

@mxmauro
Created July 5, 2022 14:13
Show Gist options
  • Save mxmauro/97de7d544c2976ca0238c7d06a0549e3 to your computer and use it in GitHub Desktop.
Save mxmauro/97de7d544c2976ca0238c7d06a0549e3 to your computer and use it in GitHub Desktop.
Update all application Go dependencies on Windows
'Run CSCRIPT update_go_deps.vbs in the folder containing your application source code
Option Explicit
Dim oShell
Dim S, Lines, Values
Set oShell = CreateObject("Wscript.Shell")
S = RunAndCapture("go list -mod=readonly -f " & Chr(34) & "{{.Path}}|{{.Indirect}}|{{.Main}}" & Chr(34) & " -m -u all")
Lines = Split(Replace(S, Chr(10), Chr(13)), Chr(13))
For Each S In Lines
Values = Split(S, "|")
If UBound(Values) = 2 Then
If LCase(Values(1)) = "false" And LCase(Values(2)) = "false" Then
Wscript.Echo "Checking " & Values(0)
Call RunAndPrint("go get -u " & Values(0))
End If
End If
Next
Wscript.Echo "Running mod tidy"
Call RunAndPrint("go mod tidy -e")
Wscript.Echo "Running mod vendor"
Call RunAndPrint("go mod vendor -e")
WScript.Quit 0
'-------------------------------------------------------------------------------
Sub RunAndPrint(S)
Dim oExec
Dim ConsoleOut, ConsoleErr
Set oExec = oShell.Exec(S)
ConsoleOut = oExec.StdOut.ReadAll
ConsoleErr = oExec.StdErr.ReadAll
If Len(ConsoleOut) > 0 Then Wscript.Echo ConsoleOut
If Len(ConsoleErr) > 0 Then Wscript.Echo ConsoleErr
Set oExec = Nothing
End Sub
Function RunAndCapture(S)
Dim oExec
Set oExec = oShell.Exec(S)
RunAndCapture = oExec.StdOut.ReadAll
Set oExec = Nothing
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment