Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bdymowski/oya tasks without run #29

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Builtin features
  • Loading branch information
bart84ek committed Apr 2, 2019
commit 922b5e6561cc5d51869153b18a7c53e9b8a7f617
4 changes: 2 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ func init() {
// Cobra supports persistent flags, which, if defined here,
// will be global for your application.
// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.oya.yaml)")
// rootCmd.PersistentFlags().BoolP("recurse", "r", false, "Recursively process Oyafiles")
rootCmd.Flags().BoolP("recurse", "r", false, "Recursively process Oyafiles")
rootCmd.PersistentFlags().BoolP("recurse", "r", false, "Recursively process Oyafiles")
rootCmd.PersistentFlags().BoolP("changeset", "c", false, "Recursively process Oyafiles")
}

// initConfig reads in config file and ENV variables if set.
Expand Down
15 changes: 4 additions & 11 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func execTask(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}

return internal.Run(cwd, taskName, taskArgs, recurse, changeset, cmd.OutOrStdout(), cmd.OutOrStderr())
}

Expand All @@ -64,8 +65,6 @@ func createCmd(name task.Name, desc string) *cobra.Command {
DisableFlagParsing: true,
RunE: execTask,
}
cmd.Flags().BoolP("recurse", "r", false, "Recursively process Oyafiles")
cmd.Flags().BoolP("changeset", "c", false, "Use the Changeset: directives")
return cmd
}

Expand All @@ -75,14 +74,13 @@ func init() {
fmt.Println(err)
}
recurse := flagRecurse()
changeset := flagChangeset()
err = addTasksCommands(cwd, recurse, changeset)
err = addTasksCommands(cwd, recurse)
if err != nil {
fmt.Println(err)
}
}

func addTasksCommands(workDir string, recurse, changeset bool) error {
func addTasksCommands(workDir string, recurse bool) error {
installDir, err := project.InstallDir()
if err != nil {
return err
Expand All @@ -95,7 +93,7 @@ func addTasksCommands(workDir string, recurse, changeset bool) error {
if err != nil {
return err
}
oyafiles, err := p.RunTargets(workDir, recurse, changeset)
oyafiles, err := p.RunTargets(workDir, recurse, false)
if err != nil {
return err
}
Expand Down Expand Up @@ -152,11 +150,6 @@ func flagRecurse() bool {
return foundInArgs(re)
}

func flagChangeset() bool {
re := regexp.MustCompile(`^-c$|^--changeset$`)
return foundInArgs(re)
}

func foundInArgs(re *regexp.Regexp) bool {
for _, arg := range os.Args {
if re.MatchString(arg) {
Expand Down
4 changes: 2 additions & 2 deletions features/builtins.feature
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ Scenario: Use plush helpers when rendering
- 3

foo: |
oya render template.txt
oya Oya.render template.txt
"""
And file ./template.txt containing
"""
Expand All @@ -140,7 +140,7 @@ Scenario: Use sprig functions when rendering (http:https://masterminds.github.io/sprig
- 3

foo: |
oya render template.txt
oya Oya.render template.txt
"""
And file ./template.txt containing
"""
Expand Down
26 changes: 12 additions & 14 deletions oya_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/DATA-DOG/godog/gherkin"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/tooploox/oya/pkg/task"
)

const SOPS_PGP_KEY = "317D 6971 DD80 4501 A6B8 65B9 0F1F D46E 2E8C 7202"
Expand All @@ -34,6 +33,8 @@ func (c *SuiteContext) MustSetUp() {
if err != nil {
panic(err)
}
fmt.Println(projectDir)
fmt.Println(c.binDir)

// overrideOyaCmd(projectDir)
setEnv(projectDir)
Expand Down Expand Up @@ -66,11 +67,12 @@ func setEnv(projectDir string) {
// to run oya tasks.
// It builds oya to a temporary directory and use it to launch Oya in scripts.
func overrideOyaCmd(projectDir string) {
executablePath := filepath.Join(projectDir, "_bin/oya")
oyaCmdOverride := fmt.Sprintf(
"function oya() { (cd %v && go build -o %v oya.go) && %v $@; }",
sourceFileDirectory(), executablePath, executablePath)
task.OyaCmdOverride = &oyaCmdOverride
// executablePath := filepath.Join(projectDir, "_bin/oya")
// "function oya() { (cd %v && go build -o %v oya.go) && %v $@; }",
// oyaCmdOverride := fmt.Sprintf(
// "function oya() { echo \"DUPAAAA\"; }")
// sourceFileDirectory(), executablePath, executablePath)
// task.OyaCmdOverride = &oyaCmdOverride
}

func (c *SuiteContext) writeFile(path, contents string) error {
Expand Down Expand Up @@ -154,14 +156,6 @@ func (c *SuiteContext) fileDoesNotExist(path string) error {
return errors.Errorf("expected %v to not exist", path)
}

type OyaCmdError struct {
Message string
}

func (e *OyaCmdError) Error() string {
return fmt.Sprintf("%v", e.Message)
}

func (c *SuiteContext) execute(command string) error {
c.stdout.Reset()
c.stderr.Reset()
Expand All @@ -174,9 +168,13 @@ func (c *SuiteContext) execute(command string) error {
}()
cmdFlds := strings.Fields(command)
oyaBin := fmt.Sprintf("%v/%v", c.binDir, cmdFlds[0])
path := fmt.Sprintf("PATH=%v:%v", c.binDir, os.Getenv("PATH"))

cmd := exec.Command(oyaBin, cmdFlds[1:]...)
cmd.Env = append(os.Environ(), path)
cmd.Stdout = c.stdout
cmd.Stderr = c.stderr

err := cmd.Run()
if err != nil {
c.lastCommandErr = errors.New(c.stderr.String())
Expand Down
2 changes: 1 addition & 1 deletion pkg/task/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ StmtLoop:
err := r.Run(ctx, stmt)
switch err.(type) {
case nil:
case interp.ExitStatus:
// case interp.ExitStatus:
case interp.ShellExitStatus:
break StmtLoop
default:
Expand Down