Skip to content

Commit fa0f8c1

Browse files
author
Oleg Sucharevich
committed
add post init flow tasks
1 parent e7a4b2f commit fa0f8c1

File tree

16 files changed

+145
-13
lines changed

16 files changed

+145
-13
lines changed

build/cli-generator.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
metadata:
22
name: cli-generator
33
description: Generate CLI entrypoints from spec file
4-
version: 0.17.0
4+
version: 0.18.0
55
maintainers:
66
- Oleg Sucharevich
77
loose: true
@@ -32,6 +32,8 @@ commands:
3232
type: bool
3333
- name: run-init-flow
3434
type: bool
35+
- name: run-post-init-flow
36+
type: bool
3537
- name: calculate-sha
3638
flags:
3739
- name: language

cmd/generate.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/root.go

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configs/templates/go.cmd.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
{{ if .cmd.root }}
88
"github.com/spf13/viper"
99
"fmt"
10+
"os"
1011
{{ end }}
1112

1213
{{- if not .cmd.loose }}
@@ -79,6 +80,7 @@ func Execute() {
7980
err := {{$name}}Cmd.Execute()
8081
if err != nil {
8182
fmt.Println(err.Error())
83+
os.Exit(1)
8284
}
8385
}
8486
{{ end }}

configs/templates/templates.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.12
44

55
require (
66
github.com/Masterminds/goutils v1.1.0 // indirect
7+
github.com/Pallinder/go-randomdata v1.2.0 // indirect
78
github.com/Shopify/ejson v1.2.1 // indirect
89
github.com/aws/aws-sdk-go v1.25.0 // indirect
910
github.com/boltdb/bolt v1.3.1 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
44
github.com/Masterminds/goutils v1.1.0 h1:zukEsf/1JZwCMgHiK3GZftabmxiCw4apj3a28RPBiVg=
55
github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
66
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
7+
github.com/Pallinder/go-randomdata v1.2.0 h1:DZ41wBchNRb/0GfsePLiSwb0PHZmT67XY00lCDlaYPg=
8+
github.com/Pallinder/go-randomdata v1.2.0/go.mod h1:yHmJgulpD2Nfrm0cR9tI/+oAgRqCQQixsA8HyRZfV9Y=
79
github.com/Shopify/ejson v1.2.1 h1:Dx0Ipn0mUgrZlzIa5oIUrH0rdSmBOyod/UJmQQK1KHo=
810
github.com/Shopify/ejson v1.2.1/go.mod h1:J8cw5GOA0l/aMOPp+uDfwNYVbeqIaBhzRkv1+76UCvk=
911
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=

greet/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/greet/greet
2+
3+
go 1.13

pkg/engine/engine.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package engine
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"os/exec"
7+
)
8+
9+
type (
10+
// Runner can run commands on the host
11+
Runner interface {
12+
Run(tasks Task) error
13+
}
14+
15+
// Options is the options that can be passed to New function
16+
Options struct {
17+
}
18+
19+
// RunOptions is the options to run a ii
20+
RunOptions struct {
21+
Path string
22+
Arguments []string
23+
EnvironmentVariables map[string]string
24+
}
25+
26+
engine struct{}
27+
)
28+
29+
// New - creates new engine
30+
func New(opt *Options) Runner {
31+
return &engine{}
32+
}
33+
34+
func (e *engine) Run(task Task) error {
35+
cmd := exec.Command(task.Path, task.Args...)
36+
37+
envs := []string{}
38+
for k, v := range task.Envs {
39+
envs = append(envs, fmt.Sprintf("%s=%s", k, v))
40+
}
41+
envs = append(envs, os.Environ()...)
42+
cmd.Env = envs
43+
cmd.Stdout = os.Stdout
44+
cmd.Stderr = os.Stderr
45+
if err := cmd.Start(); err != nil {
46+
fmt.Printf("Failed to run task %s\n", task.Name)
47+
return err
48+
}
49+
return nil
50+
}

pkg/engine/task.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package engine
2+
3+
type (
4+
Task struct {
5+
Path string
6+
Envs map[string]string
7+
Args []string
8+
Name string
9+
}
10+
)

0 commit comments

Comments
 (0)