/
cli.go
64 lines (47 loc) · 1.06 KB
/
cli.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package commands
import (
"fmt"
"os"
"strconv"
"github.com/ibejohn818/awssh/api"
"github.com/ibejohn818/awssh/config"
"github.com/manifoldco/promptui"
"github.com/spf13/cobra"
)
func AddCommands(cmd *cobra.Command, conf *config.AwsshConf) {
AddLsCmd(cmd, conf)
AddSshCmd(cmd, conf)
// AddMusshCmd(cmd, conf)
AddConfigureCmd(cmd, conf)
AddIpCmd(cmd, conf)
AddRunCmd(cmd, conf)
}
func selectInstance(coll []api.Ec2Instance, msg string, private bool) api.Ec2Instance {
for k, v := range coll {
var ln string = ""
if private {
ln = v.GetLinePrivate()
} else {
ln = v.GetLine()
}
key := strconv.Itoa((k + 1))
fmt.Printf("%3v) %v \n", key, ln)
}
prompt := promptui.Prompt{
Label: fmt.Sprintf("%v [%v-%v]", msg, strconv.Itoa(1), strconv.Itoa(len(coll))),
}
ans, err := prompt.Run()
idx, err := strconv.Atoi(ans)
if err != nil || idx <= 0 || idx > len(coll) {
fmt.Println("Invalid selection")
os.Exit(1)
}
return coll[(idx - 1)]
}
func hr() {
length := 36
for i := 0; i <= length; i++ {
fmt.Print("-")
}
fmt.Println("")
}