diff --git a/cmd/pgcli.go b/cmd/pgcli.go index 200db80..a15701c 100644 --- a/cmd/pgcli.go +++ b/cmd/pgcli.go @@ -15,10 +15,10 @@ import ( // pgcliCmd represents the pgcli command var pgcliCmd = &cobra.Command{ - Use: "pgcli [postgresID]", - Args: cobra.MaximumNArgs(1), - Short: "Open a pgcli session to a PostgreSQL database", - Long: `Open a pgcli session to a PostgreSQL database. Optionally pass the database id as an argument.`, + Use: "pgcli [postgresID]", + Short: "Open a pgcli session to a PostgreSQL database", + Long: `Open a pgcli session to a PostgreSQL database. Optionally pass the database id as an argument. +To pass arguments to pgcli, use the following syntax: render pgcli [postgresID] -- [pgcli args]`, GroupID: GroupSession.ID, } @@ -57,6 +57,14 @@ func init() { return err } + if cmd.ArgsLenAtDash() == 0 { + input.PostgresID = "" + } + + if cmd.ArgsLenAtDash() >= 0 { + input.Args = args[cmd.ArgsLenAtDash():] + } + InteractivePGCLIView(ctx, &input) return nil } diff --git a/cmd/psql.go b/cmd/psql.go index 14bb051..3c5ef2f 100644 --- a/cmd/psql.go +++ b/cmd/psql.go @@ -15,10 +15,10 @@ import ( // psqlCmd represents the psql command var psqlCmd = &cobra.Command{ - Use: "psql [postgresID]", - Args: cobra.MaximumNArgs(1), - Short: "Open a psql session to a PostgreSQL database", - Long: `Open a psql session to a PostgreSQL database. Optionally pass the database id as an argument.`, + Use: "psql [postgresID]", + Short: "Open a psql session to a PostgreSQL database", + Long: `Open a psql session to a PostgreSQL database. Optionally pass the database id as an argument. +To pass arguments to psql, use the following syntax: render psql [postgresID] -- [psql args]`, GroupID: GroupSession.ID, } @@ -57,6 +57,14 @@ func init() { return err } + if cmd.ArgsLenAtDash() == 0 { + input.PostgresID = "" + } + + if cmd.ArgsLenAtDash() >= 0 { + input.Args = args[cmd.ArgsLenAtDash():] + } + InteractivePSQLView(ctx, &input) return nil } diff --git a/cmd/rediscli.go b/cmd/rediscli.go index dc34bf7..77a4441 100644 --- a/cmd/rediscli.go +++ b/cmd/rediscli.go @@ -15,10 +15,10 @@ import ( // redisCLICmd represents the redisCLI command var redisCLICmd = &cobra.Command{ - Use: "redis-cli [redisID]", - Args: cobra.MaximumNArgs(1), - Short: "Open a redis-cli session to a Redis instance", - Long: `Open a redis-cli session to a Redis instance. Optionally pass the redis id as an argument.`, + Use: "redis-cli [redisID]", + Short: "Open a redis-cli session to a Redis instance", + Long: `Open a redis-cli session to a Redis instance. Optionally pass the redis id as an argument. +To pass arguments to redis-cli, use the following syntax: render redis-cli [redisID] -- [redis-cli args]`, GroupID: GroupSession.ID, } @@ -56,6 +56,14 @@ func init() { return err } + if cmd.ArgsLenAtDash() == 0 { + input.RedisID = "" + } + + if cmd.ArgsLenAtDash() >= 0 { + input.Args = args[cmd.ArgsLenAtDash():] + } + InteractiveRedisView(ctx, &input) return nil } diff --git a/cmd/ssh.go b/cmd/ssh.go index 71eded9..89048e9 100644 --- a/cmd/ssh.go +++ b/cmd/ssh.go @@ -16,10 +16,10 @@ import ( // sshCmd represents the ssh command var sshCmd = &cobra.Command{ - Use: "ssh [serviceID]", - Args: cobra.MaximumNArgs(1), - Short: "SSH into a service instance", - Long: `SSH into a service instance. Optionally pass the service id as an argument.`, + Use: "ssh [serviceID]", + Short: "SSH into a service instance", + Long: `SSH into a service instance. Optionally pass the service id as an argument. +To pass arguments to ssh, use the following syntax: render ssh [serviceID] -- [ssh args]`, GroupID: GroupSession.ID, } @@ -59,6 +59,14 @@ func init() { return err } + if cmd.ArgsLenAtDash() == 0 { + input.ServiceID = "" + } + + if cmd.ArgsLenAtDash() >= 0 { + input.Args = args[cmd.ArgsLenAtDash():] + } + InteractiveSSHView(ctx, &input, "SSH") return nil } diff --git a/pkg/tui/exec.go b/pkg/tui/exec.go index a907b3d..6145cce 100644 --- a/pkg/tui/exec.go +++ b/pkg/tui/exec.go @@ -48,7 +48,7 @@ func (m *ExecModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } } - return nil + return ExecDone{} }) case ExecDone: return m, func() tea.Msg { diff --git a/pkg/tui/views/psql.go b/pkg/tui/views/psql.go index b3dfd5e..4d7ce7f 100644 --- a/pkg/tui/views/psql.go +++ b/pkg/tui/views/psql.go @@ -26,6 +26,8 @@ type PSQLInput struct { Project *client.Project EnvironmentIDs []string Tool PSQLTool + + Args []string } type PSQLView struct { @@ -104,7 +106,12 @@ func loadDataPSQL(ctx context.Context, in *PSQLInput) (*exec.Cmd, error) { return nil, err } - return exec.Command(string(in.Tool), connectionInfo.ExternalConnectionString), nil + args := []string{connectionInfo.ExternalConnectionString} + for _, arg := range in.Args { + args = append(args, arg) + } + + return exec.Command(string(in.Tool), args...), nil } func hasAccessToPostgres(pg *client.PostgresDetail, userIP net.IP) (bool, error) { diff --git a/pkg/tui/views/rediscli.go b/pkg/tui/views/rediscli.go index a05106d..95e4247 100644 --- a/pkg/tui/views/rediscli.go +++ b/pkg/tui/views/rediscli.go @@ -18,6 +18,8 @@ type RedisCLIInput struct { RedisID string `cli:"arg:0"` Project *client.Project EnvironmentIDs []string + + Args []string } type RedisCLIView struct { @@ -94,6 +96,10 @@ func loadDataRedisCLI(ctx context.Context, in *RedisCLIInput) (*exec.Cmd, error) } } + for _, arg := range in.Args { + cmdArgs = append(cmdArgs, arg) + } + cmd := exec.Command("redis-cli", cmdArgs...) cmd.Env = env return cmd, nil diff --git a/pkg/tui/views/ssh.go b/pkg/tui/views/ssh.go index d3d33db..2f72f98 100644 --- a/pkg/tui/views/ssh.go +++ b/pkg/tui/views/ssh.go @@ -19,6 +19,8 @@ type SSHInput struct { ServiceID string `cli:"arg:0"` Project *client.Project EnvironmentIDs []string + + Args []string } type SSHView struct { @@ -123,7 +125,12 @@ func loadDataSSH(ctx context.Context, in *SSHInput) (*exec.Cmd, error) { return nil, fmt.Errorf("service does not support ssh") } - return exec.Command("ssh", *sshAddress), nil + args := []string{*sshAddress} + for _, arg := range in.Args { + args = append(args, arg) + } + + return exec.Command("ssh", args...), nil } func (v *SSHView) Init() tea.Cmd {