mydev/cmd/db.go
Victor Abrell 7140397a13 Initial commit: MyDev dev-environment TUI
CLI + live dashboard wrapping aws/docker/git/awsmfa for local dev:
AWS MFA auth status + expiry, dev compose stack control, container
drift vs the dev repo, git repo status, prod-data and DB-access tools.
Config-driven (~/.config/mydev/config.yaml). Dashboard runs commands
via a command palette with captured/interactive modes.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-12 14:31:58 +02:00

64 lines
1.4 KiB
Go

package cmd
import (
"fmt"
"os"
"mydev/internal/config"
"mydev/internal/run"
"github.com/spf13/cobra"
)
// devBin resolves a script under dev_dir/bin, exiting on config error.
func devBin(script string) string {
cfg, err := config.Load()
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
p, err := cfg.DevBin(script)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
return p
}
func runScript(script string, args ...string) {
if err := run.Stream("", devBin(script), args...); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
var dbCmd = &cobra.Command{
Use: "db",
Short: "Database access requests (dev/bin scripts)",
}
var dbBastCmd = &cobra.Command{
Use: "bast",
Short: "Request bastion access (request_bast_access.sh)",
Run: func(cmd *cobra.Command, args []string) { runScript("request_bast_access.sh") },
}
var dbGrantCmd = &cobra.Command{
Use: "grant [arg]",
Short: "Request a grant (grant_request.sh)",
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) { runScript("grant_request.sh", args...) },
}
var dbListCmd = &cobra.Command{
Use: "list [arg]",
Short: "List grants (grant_list.sh)",
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) { runScript("grant_list.sh", args...) },
}
func init() {
dbCmd.AddCommand(dbBastCmd, dbGrantCmd, dbListCmd)
rootCmd.AddCommand(dbCmd)
}