Created
March 31, 2022 17:36
-
-
Save weakpixel/dbe895ecf374577669904584e1ea6da3 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
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) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment