docker-register-manager/main.go

67 lines
1.5 KiB
Go
Raw Permalink Normal View History

2024-09-29 23:32:56 +03:00
package main
import (
"fmt"
2024-09-30 19:31:22 +03:00
"gitea.stuzer.link/stuzer05/docker-registry-manager/cmd"
"gitea.stuzer.link/stuzer05/docker-registry-manager/internal/app"
"github.com/joho/godotenv"
2024-10-07 12:26:44 +03:00
"log"
2024-10-02 23:04:32 +03:00
"os"
2024-10-07 12:26:44 +03:00
"path/filepath"
2024-09-29 23:32:56 +03:00
)
func main() {
2024-10-07 12:26:44 +03:00
// Get executable directory
exePath, err := os.Executable()
if err != nil {
log.Fatal("Error getting executable path:", err)
}
exeDir := filepath.Dir(exePath)
2024-09-29 23:32:56 +03:00
// Load .env file
2024-10-08 16:03:55 +03:00
godotenv.Load(filepath.Join(exeDir, ".env"))
2024-09-29 23:32:56 +03:00
2024-09-30 19:31:22 +03:00
// Initialize app
app, err := app.NewApp()
if err != nil {
fmt.Println("Error initializing app:", err)
2024-09-29 23:32:56 +03:00
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":
2024-09-30 19:31:22 +03:00
cmd.RegistryImages(app)
2024-09-29 23:32:56 +03:00
case "tags":
if len(os.Args) < 3 {
fmt.Println("Error: Please provide an image name.")
return
}
2024-09-30 19:31:22 +03:00
cmd.RegistryTags(app, os.Args[2])
2024-09-29 23:32:56 +03:00
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
}
2024-09-30 19:31:22 +03:00
cmd.RegistryRm(app, os.Args[2])
2024-09-29 23:32:56 +03:00
case "push":
if len(os.Args) < 3 {
fmt.Println("Error: Please provide an image name to push.")
return
}
2024-09-30 19:31:22 +03:00
cmd.RegistryPush(app, os.Args[2])
2024-09-29 23:32:56 +03:00
case "tag":
if len(os.Args) < 4 {
fmt.Println("Error: Please provide both source and target image names.")
return
}
2024-09-30 19:31:22 +03:00
cmd.RegistryTag(app, os.Args[2], os.Args[3])
2024-09-29 23:32:56 +03:00
default:
fmt.Println("Invalid command. Usage: registry [images|tags|rm|push|tag] <args>")
}
}