Add update command.
Signed-off-by: Odyssey <hi@odyssey346.dev>
このコミットが含まれているのは:
コミット
de39918aa8
3
.gitignore
vendored
3
.gitignore
vendored
@ -23,8 +23,5 @@ go.work
|
||||
|
||||
tmp/
|
||||
|
||||
# Gothub binary.
|
||||
gothub
|
||||
|
||||
# Fiber compressed files
|
||||
*.fiber.gz
|
62
cmd/gothub/update.go
ノーマルファイル
62
cmd/gothub/update.go
ノーマルファイル
@ -0,0 +1,62 @@
|
||||
package gothub
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
var updateCmd = &cobra.Command{
|
||||
Use: "update",
|
||||
Short: "Update GotHub.",
|
||||
Long: `This command checks for updates and re-builds GotHub. Does not work on Docker`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
update()
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(updateCmd)
|
||||
}
|
||||
|
||||
func update() {
|
||||
if os.Getenv("DOCKER") == "true" {
|
||||
println("The GotHub update command does not work on Docker. Just re-create the container with a new image.")
|
||||
os.Exit(1)
|
||||
}
|
||||
gitPull := exec.Command("git", "pull")
|
||||
var out bytes.Buffer
|
||||
gitPull.Stdout = &out
|
||||
err := gitPull.Run()
|
||||
if out.String() == "Already up to date.\r" {
|
||||
println("GotHub is already up to date.")
|
||||
os.Exit(0)
|
||||
}
|
||||
if err != nil {
|
||||
println("Couldn't run Git pull. Are you using Git?", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if runtime.GOOS == "windows" {
|
||||
err := exec.Command("go", "build", "-o", "gothub.exe").Run()
|
||||
if err != nil {
|
||||
println("Couldn't build GotHub. ", err)
|
||||
os.Exit(1)
|
||||
} else {
|
||||
println("GotHub updated successfully.")
|
||||
os.Exit(0)
|
||||
}
|
||||
} else {
|
||||
err := exec.Command("go", "build").Run()
|
||||
if err != nil {
|
||||
println("Couldn't build GotHub. ", err)
|
||||
os.Exit(1)
|
||||
} else {
|
||||
println("GotHub updated successfully.")
|
||||
os.Exit(0)
|
||||
}
|
||||
}
|
||||
}
|
読み込み中…
新しいイシューから参照
ユーザーをブロックする