diff --git a/command.go b/command.go index f714cd5..d942c6c 100644 --- a/command.go +++ b/command.go @@ -191,7 +191,7 @@ func (c *command) AtomicRun(args []string, async bool) error { } // init command - cmd, script, cleanupFunc, err := c.createCommand(argBuffer) + cmd, script, cleanupFunc, err := c.createCommand(argBuffer, args) if err != nil { return err } @@ -450,7 +450,7 @@ func (c *command) getLanguage() (*Language, error) { // create an exec.Cmd instance ready for execution // for the given argument buffer -func (c *command) createCommand(argBuffer string) (cmd *exec.Cmd, script string, cleanupFunc func(), err error) { +func (c *command) createCommand(argBuffer string, rawArgs []string) (cmd *exec.Cmd, script string, cleanupFunc func(), err error) { var ( shellCommand []string @@ -474,6 +474,11 @@ func (c *command) createCommand(argBuffer string) (cmd *exec.Cmd, script string, // add interpreter shellCommand = append(shellCommand, lang.Interpreter) + // add extra args if set + if len(lang.Args) > 0 { + shellCommand = append(shellCommand, lang.Args...) + } + if stopOnErr && lang.FlagStopOnError != "" { shellCommand = append(shellCommand, lang.FlagStopOnError) } @@ -520,14 +525,21 @@ func (c *command) createCommand(argBuffer string) (cmd *exec.Cmd, script string, } } else { - contents, err := ioutil.ReadFile(c.path) - if err != nil { - Log.Error("failed to read script") - return nil, "", nil, err - } + if lang.Name == "go" { + // make an exception for golang: invoke the source file directly and pass raw args on the commandline + shellCommand = append(shellCommand, c.path) + shellCommand = append(shellCommand, rawArgs...) + } else { - script = lang.Bang + "\n" + globalFuncs + "\n" + argBuffer + "\n" + string(contents) - shellCommand = append(shellCommand, script) + contents, err := ioutil.ReadFile(c.path) + if err != nil { + Log.Error("failed to read script") + return nil, "", nil, err + } + + script = lang.Bang + "\n" + globalFuncs + "\n" + argBuffer + "\n" + string(contents) + shellCommand = append(shellCommand, script) + } } Log.Debug("shellCommand: ", shellCommand) diff --git a/commandData.go b/commandData.go index f7b6856..c43c47b 100644 --- a/commandData.go +++ b/commandData.go @@ -279,6 +279,10 @@ func (d *commandData) init(commandsFile *CommandsFile, name string) error { useBase: d.UseBase, } + if lang == "go" && d.Exec != "" { + return errors.New("when using Go, use of the exec field is not allowed. Please a create a file in the scripts folder instead") + } + // replace globals in outputs for i, o := range cmd.outputs { out, err := commandsFile.replaceGlobals(o) diff --git a/language.go b/language.go index a109f82..12d006f 100644 --- a/language.go +++ b/language.go @@ -37,6 +37,7 @@ var ( "sh": shellLanguage(), "zsh": zshellLanguage(), "perl": perlLanguage(), + "go": goLanguage(), }, } @@ -67,6 +68,9 @@ func (langStore *languageStore) getLang(name string) (*Language, error) { type Language struct { Name string `yaml:"name"` + // extra arguments + Args []string `yaml:"args"` + // path to Interpreter Interpreter string `yaml:"interpreter"` @@ -234,3 +238,17 @@ func perlLanguage() *Language { ErrLineNumberSymbol: "line", } } + +func goLanguage() *Language { + return &Language{ + Name: "go", + Interpreter: "go", + Args: []string{"run"}, + Comment: "//", + AssignmentOperator: " = ", + VariableKeyword: "var ", + FileExtension: ".go", + CorrectErrLineNumber: true, + ErrLineNumberSymbol: "line", + } +} diff --git a/zeus/data.yml b/zeus/data.yml index 5b7acf1..2bcc778 100755 --- a/zeus/data.yml +++ b/zeus/data.yml @@ -7,7 +7,7 @@ # v0.8.10 # -buildNumber: 452 +buildNumber: 457 deadline: "" milestones: [] aliases: {}