Skip to content

Commit

Permalink
add support to set workingDir for individual commands
Browse files Browse the repository at this point in the history
  • Loading branch information
dreadl0ck committed Feb 18, 2021
1 parent 8d833a2 commit 1cd615f
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 128 deletions.
13 changes: 8 additions & 5 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ type command struct {
// the path where the script resides
path string

// root path that contains the zeus folder
root string
// workingDir path that contains the zeus folder
workingDir string

// language identifier
// set automatically via fileExtension
Expand Down Expand Up @@ -132,9 +132,12 @@ func (c *command) Run(args []string, async bool) error {
return c.AsyncRun(args)
}

err := os.Chdir(c.root)
if err != nil {
return err
if c.workingDir != "" {
Log.Debug("moving into workingDir", c.workingDir)
err := os.Chdir(c.workingDir)
if err != nil {
return err
}
}

// handle args
Expand Down
7 changes: 7 additions & 0 deletions commandData.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ type commandData struct {

// Extends sets the base configuration to use for this command
Extends string `yaml:"extends"`

// WorkingDir overwrites the working directory for this command
WorkingDir string `yaml:"workingDir"`
}

// initialize a command from a commandData instance
Expand Down Expand Up @@ -279,6 +282,10 @@ func (d *commandData) init(commandsFile *CommandsFile, name string) error {
extends: d.Extends,
}

if d.WorkingDir != "" {
cmd.workingDir = d.WorkingDir
}

if lang == "go" && d.Exec != "" {
return errors.New("when using Go, use of the exec field is not allowed. Please a create a file in the scripts folder instead")
}
Expand Down
4 changes: 3 additions & 1 deletion commandsFile.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ func parseCommandsFile(path string, flush bool) (*CommandsFile, error) {
// set working directory for all commands that are from the current commandsFile
for name := range commandsFile.Commands {
if cmd, ok := cmdMap.items[name]; ok {
cmd.root = wd
if cmd.workingDir == "" {
cmd.workingDir = wd
}
}
}

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/chzyer/logex v1.1.10 // indirect
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 // indirect
github.com/daaku/go.zipexe v1.0.1 // indirect
github.com/davecgh/go-spew v1.1.1
github.com/desertbit/glue v0.0.0-20190619185959-06de07e1e404
github.com/dreadl0ck/readline v0.0.0-20210203135358-2a7a5106ebf9
github.com/elliotchance/orderedmap v1.4.0
Expand Down
240 changes: 120 additions & 120 deletions rice-box.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ package main

// zeus version
// generated with the gen-version command
var version = "0.9.3"
var version = "0.9.4"
2 changes: 1 addition & 1 deletion zeus/commands.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ language: bash
globals:
binaryName: zeus
buildDir: bin
version: 0.9.3
version: 0.9.4

# all commands
# available fields:
Expand Down

0 comments on commit 1cd615f

Please sign in to comment.