From 05774509d686509cebb60e32fc6cc886af96e514 Mon Sep 17 00:00:00 2001 From: Pavel Vorobyov Date: Tue, 22 Oct 2019 14:22:49 +0300 Subject: [PATCH] rcfile restored --- cli/cli.go | 21 +++++++++++++++++++++ cli/handlers.go | 7 +++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/cli/cli.go b/cli/cli.go index e4d9557..8f4e998 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -152,6 +152,8 @@ func New(cfg *config.XCConfig, backend store.Backend) (*Cli, error) { cli.doMode("mode", "mode", cfg.Mode) cli.setPrompt() + cli.runRC(cfg.RCfile) + return cli, nil } @@ -487,3 +489,22 @@ func (c *Cli) setDistributeType(dtr string) { } 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) + } +} diff --git a/cli/handlers.go b/cli/handlers.go index fb3d052..6670de7 100644 --- a/cli/handlers.go +++ b/cli/handlers.go @@ -8,6 +8,8 @@ import ( "strconv" "syscall" + "github.com/viert/xc/config" + "github.com/viert/xc/passmgr" "github.com/viert/xc/remote" "github.com/viert/xc/term" @@ -365,9 +367,10 @@ func (c *Cli) doOutput(name string, argsLine string, args ...string) { return } - err := c.setOutput(argsLine) + outputFilename := config.ExpandPath(argsLine) + err := c.setOutput(outputFilename) if err == nil { - c.outputFileName = argsLine + c.outputFileName = outputFilename term.Successf("Output is copied to %s\n", c.outputFileName) } else { term.Errorf("Error setting output file to %s: %s\n", argsLine, err)