rcfile restored

This commit is contained in:
Pavel Vorobyov
2019-10-22 14:22:49 +03:00
parent f13072cc03
commit 05774509d6
2 changed files with 26 additions and 2 deletions

View File

@@ -152,6 +152,8 @@ func New(cfg *config.XCConfig, backend store.Backend) (*Cli, error) {
cli.doMode("mode", "mode", cfg.Mode) cli.doMode("mode", "mode", cfg.Mode)
cli.setPrompt() cli.setPrompt()
cli.runRC(cfg.RCfile)
return cli, nil return cli, nil
} }
@@ -487,3 +489,22 @@ func (c *Cli) setDistributeType(dtr string) {
} }
remote.SetDistributeType(c.distributeType) remote.SetDistributeType(c.distributeType)
} }
func (c *Cli) runRC(rcfile string) {
f, err := os.Open(rcfile)
if err != nil {
if !os.IsNotExist(err) {
term.Errorf("Error loading rcfile: %s\n", err)
}
return
}
defer f.Close()
term.Successf("Running rcfile %s...", rcfile)
sc := bufio.NewScanner(f)
for sc.Scan() {
cmd := sc.Text()
fmt.Println(term.Green(cmd))
c.OneCmd(cmd)
}
}

View File

@@ -8,6 +8,8 @@ import (
"strconv" "strconv"
"syscall" "syscall"
"github.com/viert/xc/config"
"github.com/viert/xc/passmgr" "github.com/viert/xc/passmgr"
"github.com/viert/xc/remote" "github.com/viert/xc/remote"
"github.com/viert/xc/term" "github.com/viert/xc/term"
@@ -365,9 +367,10 @@ func (c *Cli) doOutput(name string, argsLine string, args ...string) {
return return
} }
err := c.setOutput(argsLine) outputFilename := config.ExpandPath(argsLine)
err := c.setOutput(outputFilename)
if err == nil { if err == nil {
c.outputFileName = argsLine c.outputFileName = outputFilename
term.Successf("Output is copied to %s\n", c.outputFileName) term.Successf("Output is copied to %s\n", c.outputFileName)
} else { } else {
term.Errorf("Error setting output file to %s: %s\n", argsLine, err) term.Errorf("Error setting output file to %s: %s\n", argsLine, err)