Skip to content
This repository has been archived by the owner on Sep 29, 2021. It is now read-only.

Commit

Permalink
feat: support to read output from a file
Browse files Browse the repository at this point in the history
  • Loading branch information
suzuki-shunsuke committed Oct 12, 2020
1 parent 72cc739 commit c2bce67
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
1 change: 1 addition & 0 deletions pkg/config/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Task struct {
Output Script
Input Script
InputFile string `yaml:"input_file"`
OutputFile string `yaml:"output_file"`
Import string
}

Expand Down
38 changes: 24 additions & 14 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,25 @@ func (ctrl Controller) readTemplateFile(p, wd string, tpl *config.Template) erro
return nil
}

func (ctrl Controller) readScript(p, wd string, scr *config.Script) error {
if p == "" {
return nil
}
if !filepath.IsAbs(p) {
p = filepath.Join(wd, p)
}
result, err := ctrl.FileReader.Read(p)
if err != nil {
return err
}
if prog, err := expr.New(result.Text); err != nil {
return err
} else {
scr.Prog = prog
}
return nil
}

func (ctrl Controller) ReadExternalFiles(ctx context.Context, wd string) error { //nolint:gocognit
for i, phase := range ctrl.Config.Phases {
for j, task := range phase.Tasks {
Expand Down Expand Up @@ -421,20 +440,11 @@ func (ctrl Controller) ReadExternalFiles(ctx context.Context, wd string) error {
return err
}
}
if task.InputFile != "" {
p := task.InputFile
if !filepath.IsAbs(p) {
p = filepath.Join(wd, p)
}
result, err := ctrl.FileReader.Read(p)
if err != nil {
return err
}
if prog, err := expr.New(result.Text); err != nil {
return err
} else {
task.Input.Prog = prog
}
if err := ctrl.readScript(task.InputFile, wd, &task.Input); err != nil {
return err
}
if err := ctrl.readScript(task.OutputFile, wd, &task.Output); err != nil {
return err
}
phase.Tasks[j] = task
}
Expand Down

0 comments on commit c2bce67

Please sign in to comment.