Skip to content

Commit d820678

Browse files
authored
Merge pull request #22 from dung13890/develop
refs #shell into multiple server
2 parents f8a5282 + c60edbb commit d820678

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

cmd/shell.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"github.com/dung13890/deploy-tool/config"
6+
"github.com/dung13890/deploy-tool/remote"
7+
"github.com/urfave/cli/v2"
8+
"log"
9+
)
10+
11+
type shell struct {
12+
config config.Configuration
13+
privateKey string
14+
}
15+
16+
func NewShell() *cli.Command {
17+
return &cli.Command{
18+
Name: "shell",
19+
Aliases: []string{"s"},
20+
Usage: "Running shell into multiple servers",
21+
Flags: []cli.Flag{
22+
config.Load,
23+
config.Identity,
24+
},
25+
Action: func(ctx *cli.Context) error {
26+
s := &shell{}
27+
err := s.config.ReadFile(ctx.String("config"))
28+
if err != nil {
29+
log.Fatal(err)
30+
}
31+
s.privateKey = ctx.String("identity")
32+
s.exec()
33+
return nil
34+
},
35+
}
36+
}
37+
38+
func (s *shell) exec() error {
39+
var r remote.Remote
40+
41+
if s.config.Server.Address == "127.0.0.1" || s.config.Server.Address == "localhost" {
42+
r = &remote.Localhost{}
43+
} else {
44+
r = &remote.Server{}
45+
}
46+
defer r.Close()
47+
48+
fmt.Println("Running shell into multiple servers:")
49+
50+
return nil
51+
}

main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ func main() {
1515
ping := cmd.NewPing()
1616
deploy := cmd.NewDeploy()
1717
init := cmd.NewInit()
18+
shell := cmd.NewShell()
1819

1920
app := &cli.App{
2021
Name: "doo",
@@ -26,6 +27,7 @@ func main() {
2627
init,
2728
ping,
2829
deploy,
30+
shell,
2931
},
3032
}
3133
err := app.Run(os.Args)

0 commit comments

Comments
 (0)