docker-register-manager/main.go

67 lines
1.5 KiB
Go

package main
import (
"fmt"
"os"
"path/filepath"
"runtime"
"gitea.stuzer.link/stuzer05/docker-registry-manager/cmd"
"gitea.stuzer.link/stuzer05/docker-registry-manager/internal/app"
"github.com/joho/godotenv"
)
func main() {
// Load .env file
_, b, _, _ := runtime.Caller(0)
err := godotenv.Load(filepath.Join(filepath.Dir(b), ".env"))
if err != nil {
fmt.Println("Error loading .env file:", err)
return
}
// Initialize app
app, err := app.NewApp()
if err != nil {
fmt.Println("Error initializing app:", err)
return
}
if len(os.Args) < 2 {
fmt.Println("Invalid command. Usage: registry [images|tags|rm|push|tag] <args>")
return
}
switch os.Args[1] {
case "images":
cmd.RegistryImages(app)
case "tags":
if len(os.Args) < 3 {
fmt.Println("Error: Please provide an image name.")
return
}
cmd.RegistryTags(app, os.Args[2])
case "rm":
if len(os.Args) < 3 {
fmt.Println("Error: Please provide an image name and optionally a tag (e.g., my-image or my-image:latest).")
return
}
cmd.RegistryRm(app, os.Args[2])
case "push":
if len(os.Args) < 3 {
fmt.Println("Error: Please provide an image name to push.")
return
}
cmd.RegistryPush(app, os.Args[2])
case "tag":
if len(os.Args) < 4 {
fmt.Println("Error: Please provide both source and target image names.")
return
}
cmd.RegistryTag(app, os.Args[2], os.Args[3])
default:
fmt.Println("Invalid command. Usage: registry [images|tags|rm|push|tag] <args>")
}
}