Skip to content

Commit

Permalink
Merge pull request #17 from ova777/master
Browse files Browse the repository at this point in the history
Added the db command
  • Loading branch information
sibprogrammer authored Oct 4, 2023
2 parents 12b828e + 360f0b5 commit b22a910
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 6 deletions.
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

0 comments on commit b22a910

Please sign in to comment.