choice between distribute types

This commit is contained in:
Pavel Vorobyov
2019-09-25 12:53:08 +03:00
parent 1328d7d68c
commit e659ccb06f
6 changed files with 48 additions and 1 deletions

View File

@@ -34,6 +34,7 @@ type Cli struct {
mode execMode
user string
raiseType remote.RaiseType
distributeType remote.CopyType
raisePasswd string
remoteTmpDir string
delay int
@@ -113,6 +114,7 @@ func New(cfg *config.XCConfig, backend store.Backend) (*Cli, error) {
cli.connectTimeout = cfg.SSHConnectTimeout
cli.remoteTmpDir = cfg.RemoteTmpdir
cli.setRaiseType(cfg.RaiseType)
cli.setDistributeType(cfg.Distribute)
// output
cli.outputFileName = ""
@@ -460,6 +462,7 @@ func (c *Cli) setRaiseType(rt string) {
c.raiseType = remote.RTNone
default:
term.Errorf("Unknown raise type: %s\n", rt)
return
}
if c.raiseType != currentRaiseType {
@@ -468,3 +471,17 @@ func (c *Cli) setRaiseType(rt string) {
}
remote.SetRaise(c.raiseType)
}
func (c *Cli) setDistributeType(dtr string) {
switch dtr {
case "tar":
c.distributeType = remote.CTTar
case "scp":
c.distributeType = remote.CTScp
default:
term.Errorf("Unknown distribute type: %s\n", dtr)
return
}
term.Successf("distribute_type set to %s\n", dtr)
remote.SetDistributeType(c.distributeType)
}

View File

@@ -24,6 +24,7 @@ func newCompleter(store *store.Store, commands []string) *completer {
x.handlers["debug"] = onOffCompleter()
x.handlers["progressbar"] = onOffCompleter()
x.handlers["prepend_hostnames"] = onOffCompleter()
x.handlers["use_password_manager"] = onOffCompleter()
x.handlers["raise"] = staticCompleter([]string{"none", "su", "sudo"})
x.handlers["interpreter"] = staticCompleter([]string{"none", "su", "sudo"})
x.handlers["exec"] = x.completeExec
@@ -39,6 +40,7 @@ func newCompleter(store *store.Store, commands []string) *completer {
x.handlers["s_runscript"] = x.completeDistribute
x.handlers["c_runscript"] = x.completeDistribute
x.handlers["p_runscript"] = x.completeDistribute
x.handlers["distribute_type"] = staticCompleter([]string{"tar", "scp"})
helpTopics := append(commands, "expressions", "config", "rcfiles", "passmgr")
x.handlers["help"] = staticCompleter(helpTopics)

View File

@@ -49,6 +49,7 @@ func (c *Cli) setupCmdHandlers() {
c.handlers["c_runscript"] = c.doCRunScript
c.handlers["p_runscript"] = c.doPRunScript
c.handlers["use_password_manager"] = c.doUsePasswordManager
c.handlers["distribute_type"] = c.doDistributeType
commands := make([]string, len(c.handlers))
i := 0
@@ -148,6 +149,18 @@ func (c *Cli) doRaise(name string, argsLine string, args ...string) {
c.setRaiseType(args[0])
}
func (c *Cli) doDistributeType(name string, argsLine string, args ...string) {
if len(args) < 1 {
dtype := "scp"
if c.distributeType == remote.CTTar {
dtype = "tar"
}
term.Warnf("distribute_type is %s\n", dtype)
return
}
c.setDistributeType(args[0])
}
func (c *Cli) doPasswd(name string, argsLine string, args ...string) {
passwd, err := c.rl.ReadPassword("Set su/sudo password: ")
if err != nil {