Set module to git.abrell.se/victor/mydev so it installs from the private Gitea host, and add an MIT LICENSE. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
64 lines
1.4 KiB
Go
64 lines
1.4 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"git.abrell.se/victor/mydev/internal/config"
|
|
"git.abrell.se/victor/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)
|
|
}
|