All checks were successful
build and deploy kleinTodo / build (push) Successful in 35s
96 lines
1.7 KiB
Go
96 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log"
|
|
"log/slog"
|
|
"net/mail"
|
|
"os"
|
|
"os/exec"
|
|
"runtime/debug"
|
|
|
|
"gitea.kleinsense.nl/DariusKlein/kleinTodo/client/todo/clientCommon/config"
|
|
"github.com/urfave/cli/v3"
|
|
)
|
|
|
|
var cfg config.Config
|
|
|
|
func main() {
|
|
var err error
|
|
cfg, err = config.ReadConfig()
|
|
if err != nil {
|
|
slog.Error(err.Error())
|
|
}
|
|
|
|
app := &cli.Command{
|
|
Name: "Todo",
|
|
Usage: "kleinTodo client",
|
|
UsageText: "Todo [command] [arguments...]",
|
|
Version: "v0.9.0",
|
|
HideVersion: true,
|
|
Authors: []any{
|
|
mail.Address{
|
|
Name: "Darius",
|
|
Address: "darius.klein@dariusklein.nl",
|
|
},
|
|
},
|
|
DefaultCommand: "todo",
|
|
Commands: commands(),
|
|
}
|
|
|
|
if err := app.Run(context.Background(), os.Args); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func commands() []*cli.Command {
|
|
return []*cli.Command{
|
|
config.Category(),
|
|
Login(),
|
|
Sync(),
|
|
Add(),
|
|
Todo(),
|
|
Register(),
|
|
{
|
|
Name: "update",
|
|
Usage: "Update the vennexCLI to a specific version",
|
|
Flags: []cli.Flag{
|
|
&cli.StringFlag{
|
|
Name: "version",
|
|
Usage: "The version label to install (e.g., v1.2.0, main, latest)",
|
|
Value: "latest",
|
|
},
|
|
},
|
|
Action: runUpdate,
|
|
},
|
|
}
|
|
}
|
|
|
|
func runUpdate(ctx context.Context, command *cli.Command) error {
|
|
var pkgPath = "unknown"
|
|
info, ok := debug.ReadBuildInfo()
|
|
if ok {
|
|
pkgPath = info.Main.Path
|
|
}
|
|
|
|
pkg := fmt.Sprintf("%s@%s", pkgPath, command.String("version"))
|
|
|
|
slog.Info(fmt.Sprintf("Updating to %s...\n", pkg))
|
|
|
|
cmd := exec.Command("go", "install", pkg)
|
|
|
|
cmd.Stdout = os.Stdout
|
|
cmd.Stderr = os.Stderr
|
|
|
|
err := cmd.Run()
|
|
if err != nil {
|
|
slog.Error("Update failed:", "error", err)
|
|
return err
|
|
}
|
|
|
|
slog.Info("Update successful!")
|
|
|
|
return nil
|
|
}
|