Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the db command #16

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions cmd/db.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 1999-2023. Plesk International GmbH.

package cmd

import (
"github.com/plesk/pleskapp/plesk/internal/actions"
"github.com/plesk/pleskapp/plesk/internal/config"
"github.com/plesk/pleskapp/plesk/internal/locales"
"github.com/spf13/cobra"
)

var dbCmd = &cobra.Command{
Use: "db [SERVER]",
Short: locales.L.Get("server.db.description"),
RunE: func(cmd *cobra.Command, args []string) error {
server, err := config.GetServerByArgs(args)
if err != nil {
return err
}

return actions.ServerSSH(*server, "plesk db", true)
},
}
6 changes: 4 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
package cmd

import (
"io/ioutil"
"log"

appsCmd "github.com/plesk/pleskapp/plesk/cmd/apps"
databasesCmd "github.com/plesk/pleskapp/plesk/cmd/databases"
domainsCmd "github.com/plesk/pleskapp/plesk/cmd/domains"
serversCmd "github.com/plesk/pleskapp/plesk/cmd/servers"
syncCmd "github.com/plesk/pleskapp/plesk/cmd/sync"
"github.com/spf13/cobra"
"io/ioutil"
"log"
)

var rootCmd = &cobra.Command{
Expand All @@ -30,6 +31,7 @@ func Execute() error {
contextCmd,
loginCmd,
sshCmd,
dbCmd,
webCmd,
completionCmd,
pleskCmd,
Expand Down
2 changes: 1 addition & 1 deletion cmd/servers/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var SSHCmd = &cobra.Command{
return err
}

return actions.ServerSSH(*server, additionalCommand)
return actions.ServerSSH(*server, additionalCommand, false)
},
}

Expand Down
11 changes: 8 additions & 3 deletions internal/actions/servers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ package actions

import (
"fmt"
"github.com/pkg/browser"
"os"
"os/exec"
"sort"
"text/tabwriter"
"time"

"github.com/pkg/browser"
"github.com/plesk/pleskapp/plesk/internal/api"
"github.com/plesk/pleskapp/plesk/internal/api/factory"
"github.com/plesk/pleskapp/plesk/internal/config"
Expand Down Expand Up @@ -108,14 +108,19 @@ func ServerLogin(host types.Server, generateOnly bool) error {
return nil
}

func ServerSSH(host types.Server, additionalCommand string) error {
func ServerSSH(host types.Server, additionalCommand string, interactiveMode bool) error {
if additionalCommand == "" {
fmt.Printf("Login to %s using SSH...\n", host.Host)
} else {
fmt.Printf("Attempt to execute '%s' at %s via SSH...\n", additionalCommand, host.Host)
}

cmd := exec.Command("ssh", host.Host, additionalCommand)
args := []string{host.Host, additionalCommand}
if interactiveMode {
args = append([]string{"-t"}, args...)
}

cmd := exec.Command("ssh", args...)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
Expand Down
1 change: 1 addition & 0 deletions internal/locales/locales.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func init() {
"server.login.generate.flag": "Only generate the link (without autologin attempt)",
"server.ssh.description": "Login to server using SSH",
"server.ssh.flag.command": "Command to execute",
"server.db.description": "Run Plesk Database Shell using SSH",

"errors.server.remove.failure": "Could not remove server %s: %s",
"errors.feature.not.supported": "Feature %s is not supported on Windows",
Expand Down