2025-01-11 23:26:47 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2025-01-16 12:34:48 +01:00
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"path"
|
2025-01-11 23:26:47 +01:00
|
|
|
|
2025-01-16 12:34:48 +01:00
|
|
|
"git.defalsify.org/vise.git/logging"
|
|
|
|
|
|
|
|
"git.grassecon.net/grassrootseconomics/sarafu-vise/config"
|
|
|
|
"git.grassecon.net/grassrootseconomics/visedriver/storage"
|
|
|
|
"git.grassecon.net/grassrootseconomics/sarafu-vise/internal/cmd"
|
2025-01-16 14:50:18 +01:00
|
|
|
"git.grassecon.net/grassrootseconomics/sarafu-vise/handlers/application"
|
2025-01-16 12:34:48 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
logg = logging.NewVanilla().WithContextKey("SessionId")
|
|
|
|
scriptDir = path.Join("services", "registration")
|
2025-01-11 23:26:47 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2025-01-16 12:34:48 +01:00
|
|
|
config.LoadConfig()
|
|
|
|
|
|
|
|
var sessionId string
|
|
|
|
var connStr string
|
|
|
|
|
|
|
|
flag.StringVar(&sessionId, "session-id", "075xx2123", "session id")
|
|
|
|
flag.StringVar(&connStr, "c", "", "connection string")
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
|
|
|
|
if connStr == "" {
|
|
|
|
connStr = config.DbConn()
|
|
|
|
}
|
|
|
|
connData, err := storage.ToConnData(connStr)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, "connstr err: %v\n", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2025-01-11 23:26:47 +01:00
|
|
|
ctx := context.Background()
|
2025-01-16 12:34:48 +01:00
|
|
|
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
2025-01-16 14:50:18 +01:00
|
|
|
|
2025-01-16 12:34:48 +01:00
|
|
|
pfp := path.Join(scriptDir, "pp.csv")
|
2025-01-16 14:50:18 +01:00
|
|
|
flagParser, err := application.NewFlagManager(pfp)
|
2025-01-16 12:34:48 +01:00
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, "flagparser fail: %v\n", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
x := cmd.NewCmd(connData, sessionId, flagParser)
|
|
|
|
err = x.Parse(flag.Args())
|
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, "cmd parse fail: %v\n", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
logg.Infof("start command", "conn", connData, "subcmd", x)
|
|
|
|
|
|
|
|
menuStorageService := storage.NewMenuStorageService(connData, "")
|
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, "menu storage service error: %v\n", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = x.Exec(ctx, menuStorageService)
|
2025-01-11 23:26:47 +01:00
|
|
|
if err != nil {
|
2025-01-16 12:34:48 +01:00
|
|
|
fmt.Fprintf(os.Stderr, "cmd exec error: %v\n", err)
|
|
|
|
os.Exit(1)
|
2025-01-11 23:26:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|