Skip to content

Commit 07eb85f

Browse files
committed
add shell to config
1 parent f8239d7 commit 07eb85f

5 files changed

Lines changed: 31 additions & 19 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ lets run --debug --level=info
4444
## lets.yaml
4545

4646
```yaml
47+
shell: bash
4748
commands:
4849
[name]:
4950
description: string
@@ -96,7 +97,7 @@ Yet there is no binaries
9697
- [x] docopts as repeated flags, joined in string
9798
- [x] pass opts as is if cmd is an array
9899
- [x] file hashes (checksums)
99-
- [ ] global checksums
100+
- [ ] global checksums (check if some commands use checksum so we can skip its calculation)
100101
- [ ] multiple checksums in one command (kv)
101102
- [x] depends on other commands
102103
- [ ] inherit configs

commands/command/command.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type Command struct {
2828
}
2929

3030
// TODO interface{} must be replaced
31-
func NewCommand(name string, rawCommand map[string]interface{}) Command {
31+
func NewCommand(name string, rawCommand map[interface{}]interface{}) Command {
3232
newCmd := Command{
3333
Name: name,
3434
Env: make(map[string]string),
@@ -85,17 +85,19 @@ func NewCommand(name string, rawCommand map[string]interface{}) Command {
8585
}
8686

8787
if checksum, ok := rawCommand[CHECKSUM]; ok {
88-
var files []string
89-
for _, value := range checksum.([]interface{}) {
90-
// TODO validate if command is realy exists - in validate
91-
files = append(files, value.(string))
92-
}
93-
checksum, err := calculateChecksum(files)
94-
if err == nil {
95-
newCmd.Checksum = checksum
96-
} else {
97-
// TODO return error or caclulate checksum upper in the code
98-
fmt.Printf("error while checksum %s\n", err)
88+
if patterns, ok := checksum.([]interface{}); ok {
89+
var files []string
90+
for _, value := range patterns {
91+
// TODO validate if command is realy exists - in validate
92+
files = append(files, value.(string))
93+
}
94+
checksum, err := calculateChecksum(files)
95+
if err == nil {
96+
newCmd.Checksum = checksum
97+
} else {
98+
// TODO return error or caclulate checksum upper in the code
99+
fmt.Printf("error while checksum %s\n", err)
100+
}
99101
}
100102
}
101103
return newCmd

commands/run.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ func composeEnvs(envs ...[]string) []string {
4848
}
4949

5050
func runCmd(cmdToRun command.Command, cfg *config.Config, out io.Writer, isChild bool) error {
51-
// TODO get user's current shell
52-
cmd := exec.Command("sh", "-c", cmdToRun.Cmd)
51+
cmd := exec.Command(cfg.Shell, "-c", cmdToRun.Cmd)
5352
// setup std out and err
5453
cmd.Stdout = out
5554
cmd.Stderr = out

config/config.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ import (
1212
var (
1313
// COMMANDS is a top-level directive. Includes all commands to run
1414
COMMANDS = "commands"
15+
SHELL = "shell"
1516
)
1617

1718
// Config is a struct for loaded config file
1819
type Config struct {
1920
WorkDir string
2021
FilePath string
2122
Commands map[string]command.Command
23+
Shell string
2224
}
2325

2426
// Load a config from file
@@ -75,24 +77,30 @@ func newConfig() *Config {
7577

7678
// UnmarshalYAML unmarshals a config
7779
func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
78-
rawKeyValue := make(map[string]map[string]map[string]interface{})
80+
rawKeyValue := make(map[string]interface{})
7981

8082
if err := unmarshal(&rawKeyValue); err != nil {
8183
return err
8284
}
8385

8486
if cmds, ok := rawKeyValue[COMMANDS]; ok {
85-
if err := c.loadCommands(cmds); err != nil {
87+
if err := c.loadCommands(cmds.(map[interface{}]interface{})); err != nil {
8688
return err
8789
}
8890
}
91+
92+
if shell, ok := rawKeyValue[SHELL]; ok {
93+
c.Shell = fmt.Sprintf("%s", shell)
94+
}
95+
8996
return nil
9097
}
9198

9299
// TODO refactor
93-
func (c *Config) loadCommands(cmds map[string]map[string]interface{}) error {
100+
func (c *Config) loadCommands(cmds map[interface{}]interface{}) error {
94101
for key, value := range cmds {
95-
c.Commands[key] = command.NewCommand(key, value)
102+
keyStr := key.(string)
103+
c.Commands[keyStr] = command.NewCommand(keyStr, value.(map[interface{}]interface{}))
96104
}
97105
return nil
98106
}

lets.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
shell: bash
2+
13
env:
24

35
eval_env:

0 commit comments

Comments
 (0)