Skip to content

Commit

Permalink
- Passing Function to script command.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kristoffer Ahl committed Apr 4, 2020
1 parent 0b3f59c commit 7964ce2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cmd/centry/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func NewRuntime(inputArgs []string, context *Context) (*Runtime, error) {
GlobalOptions: options,
Command: cmd,
Script: script,
Function: fn.Name,
Function: *fn,
}
cliCmd := scriptCmd.ToCLICommand()

Expand Down
12 changes: 6 additions & 6 deletions cmd/centry/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ type ScriptCommand struct {
Command config.Command
GlobalOptions *cmd.OptionsSet
Script shell.Script
Function string
Function shell.Function
}

// GetCommandInvocation returns the command invocation string
func (sc *ScriptCommand) GetCommandInvocation() string {
return strings.Replace(sc.Function, sc.Script.FunctionNameSplitChar(), " ", -1)
return strings.Replace(sc.Function.Name, sc.Script.FunctionNameSplitChar(), " ", -1)
}

// GetCommandInvocationPath returns the command invocation path
Expand Down Expand Up @@ -54,7 +54,7 @@ func (sc *ScriptCommand) ToCLICommand() *cli.Command {

// Run builds the source and executes it
func (sc *ScriptCommand) Run(c *cli.Context, args []string) int {
sc.Log.Debugf("Executing command \"%v\"", sc.Function)
sc.Log.Debugf("Executing command \"%v\"", sc.Function.Name)

var source string
switch sc.Script.Language() {
Expand All @@ -76,11 +76,11 @@ func (sc *ScriptCommand) Run(c *cli.Context, args []string) int {
}
}

sc.Log.Errorf("Command %v exited with error! %v", sc.Function, err)
sc.Log.Errorf("Command %v exited with error! %v", sc.Function.Name, err)
return exitCode
}

sc.Log.Debugf("Finished executing command %v...", sc.Function)
sc.Log.Debugf("Finished executing command %v...", sc.Function.Name)
return 0
}

Expand Down Expand Up @@ -117,7 +117,7 @@ func generateBashSource(c *cli.Context, sc *ScriptCommand, args []string) string

source = append(source, "")
source = append(source, "# Executing command")
source = append(source, fmt.Sprintf("%s %s", sc.Function, strings.Join(args, " ")))
source = append(source, fmt.Sprintf("%s %s", sc.Function.Name, strings.Join(args, " ")))

return strings.Join(source, "\n")
}

0 comments on commit 7964ce2

Please sign in to comment.