Created
March 30, 2022 11:56
-
-
Save weakpixel/8501a0dabeeb800ef38b6d1cc9fa1e72 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"os" | |
"github.com/hashicorp/hcl/v2/hclsimple" | |
) | |
var ( | |
exampleHCL = ` | |
task "first_task" { | |
exec "list_current_dir" { | |
command = "ls ." | |
} | |
exec "list_var_dir" { | |
command = "ls /var" | |
} | |
} | |
` | |
) | |
func main() { | |
config := &Config{} | |
err := hclsimple.Decode("example.hcl", []byte(exampleHCL), nil, config) | |
if err != nil { | |
fmt.Println(err) | |
os.Exit(1) | |
} | |
for _, task := range config.Tasks { | |
fmt.Printf("Task: %s\n", task.Name) | |
for _, step := range task.Steps { | |
fmt.Printf(" Step: %s %q\n", step.Name, step.Command) | |
err = step.Run() | |
if err != nil { | |
fmt.Println(err) | |
os.Exit(1) | |
} | |
} | |
} | |
} | |
type Config struct { | |
Tasks []*Task `hcl:"task,block"` | |
} | |
type Task struct { | |
Name string `hcl:"name,label"` | |
Steps []*ExecStep `hcl:"exec,block"` | |
} | |
type ExecStep struct { | |
Name string `hcl:"name,label"` | |
Command string `hcl:"command"` | |
} | |
func (s *ExecStep) Run() error { | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment