forked from davrodpin/mole
-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_alias_remote.go
53 lines (43 loc) · 1.15 KB
/
add_alias_remote.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
package cmd
import (
"errors"
"fmt"
"os"
"github.com/davrodpin/mole/alias"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
const (
addAliasRemoteDoc = `Adds an alias for a ssh tunneling configuration by saving a set of start
command flags so it can be reused later.
The alias configuration file is saved under the ".mole" directory, inside the
user home directory.
`
)
var addAliasRemoteCmd = &cobra.Command{
Use: "remote [name]",
Short: "Adds an alias for a ssh tunneling configuration",
Long: fmt.Sprintf("%s\n%s", addAliasRemoteDoc, RemoteForwardDoc),
Args: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return errors.New("alias name not provided")
}
conf.TunnelType = "remote"
aliasName = args[0]
return nil
},
Run: func(cmd *cobra.Command, arg []string) {
if err := alias.Add(conf.ParseAlias(aliasName)); err != nil {
log.WithError(err).Error("failed to add tunnel alias")
os.Exit(1)
}
},
}
func init() {
err := bindFlags(conf, addAliasRemoteCmd)
if err != nil {
log.WithError(err).Error("error parsing command line arguments")
os.Exit(1)
}
addAliasCmd.AddCommand(addAliasRemoteCmd)
}