Skip to content

Commit

Permalink
FEATURE: support for usql
Browse files Browse the repository at this point in the history
  • Loading branch information
skurfuerst committed Jan 1, 2024
1 parent 620bd21 commit 8756a65
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
19 changes: 16 additions & 3 deletions internal/app/commands/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,17 @@ func BuildMysqlCommand() *cobra.Command {
dbPassword := ""

var mysqlCommand = &cobra.Command{
Use: "mysql [cli|mycli|sequelace|beekeeper] (extra-params)",
Use: "mysql [usql|cli|mycli|sequelace|beekeeper] (extra-params)",
DisableFlagsInUseLine: true,
ValidArgs: []string{"cli", "mycli", "sequelace", "beekeeper"},
ValidArgs: []string{"usql", "cli", "mycli", "sequelace", "beekeeper"},
Args: cobra.MinimumNArgs(1),
Short: "Build a mysql connection and enter it via one of the given tools",
Long: `
drop into a MySQL CLI to the given target
drop into a MySQL CLI to the given target.
`,
Run: func(cmd *cobra.Command, args []string) {
allowedArgs := map[string]bool{
"usql": true,
"cli": true,
"mycli": true,
"sequelace": true,
Expand All @@ -68,6 +69,18 @@ drop into a MySQL CLI to the given target
defer db.Close()

switch args[0] {
case "usql":
usql := exec.Command(
"usql",
fmt.Sprintf("mysql://%s:%[email protected]:%d/%s", dbUser, dbPassword, localDbProxyPort, dbName),
)
usql.Stdout = os.Stdout
usql.Stderr = os.Stderr
usql.Stdin = os.Stdin

usql.Run()

break
case "cli":
mysqlArgs := []string{
"--host=127.0.0.1",
Expand Down
17 changes: 15 additions & 2 deletions internal/app/commands/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,17 @@ func BuildPostgresCommand() *cobra.Command {
dbPassword := ""

var postgresCommand = &cobra.Command{
Use: "postgres [cli|pgcli|beekeeper] (extra-params)",
Use: "postgres [usql|cli|pgcli|beekeeper] (extra-params)",
DisableFlagsInUseLine: true,
ValidArgs: []string{"cli", "pgcli", "beekeeper"},
ValidArgs: []string{"usql", "cli", "pgcli", "beekeeper"},
Args: cobra.MinimumNArgs(1),
Short: "Build a postgres connection and enter it via one of the given tools",
Long: `
drop into a MySQL CLI to the given target
`,
Run: func(cmd *cobra.Command, args []string) {
allowedArgs := map[string]bool{
"usql": true,
"cli": true,
"pgcli": true,
"beekeeper": true,
Expand All @@ -67,6 +68,18 @@ drop into a MySQL CLI to the given target
defer db.Close()

switch args[0] {
case "usql":
usql := exec.Command(
"usql",
fmt.Sprintf("postgres://%s:%[email protected]:%d/%s", dbUser, dbPassword, localDbProxyPort, dbName),
)
usql.Stdout = os.Stdout
usql.Stderr = os.Stderr
usql.Stdin = os.Stdin

usql.Run()

break
case "cli":
psqlArgs := []string{
"--host=127.0.0.1",
Expand Down

0 comments on commit 8756a65

Please sign in to comment.