/
commands.go
34 lines (24 loc) · 909 Bytes
/
commands.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package term
import (
"strings"
"github.com/elseano/rundown/pkg/renderer"
"github.com/elseano/rundown/pkg/util"
)
func HandleCommands(spinner Spinner, context *renderer.Context) func(s string) {
const changeSpinnerTitleCommand = "R;SETSPINNER "
const setEnvironmentCommand = "R;SETENV "
return func(command string) {
util.Logger.Debug().Msgf("Got command: %s", command)
switch {
case strings.HasPrefix(command, changeSpinnerTitleCommand):
message := command[len(changeSpinnerTitleCommand):]
util.Logger.Debug().Msgf("Set spinner title %s", message)
spinner.NewStep(message)
case strings.HasPrefix(command, setEnvironmentCommand):
_args := command[len(setEnvironmentCommand)-1:]
args := strings.SplitN(_args, "=", 2)
util.Logger.Debug().Msgf("Got environment %s = %s", strings.TrimSpace(args[0]), args[1])
context.Env[strings.TrimSpace(args[0])] = args[1]
}
}
}