Skip to content

Commit

Permalink
task: Add -c/--config option for custom Taskfile location
Browse files Browse the repository at this point in the history
  • Loading branch information
tonobo committed Jan 31, 2019
1 parent 19a813c commit 52de065
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 28 deletions.
41 changes: 22 additions & 19 deletions cmd/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,25 +97,27 @@ func main() {
}

var (
versionFlag bool
init bool
list bool
listHidden bool
withDeps bool
status bool
force bool
watch bool
verbose bool
silent bool
dry bool
update bool
dir string
versionFlag bool
init bool
list bool
listHidden bool
withDeps bool
status bool
force bool
watch bool
verbose bool
taskfileLocation string
silent bool
dry bool
update bool
dir string
)

pflag.BoolVar(&versionFlag, "version", false, "show Task version")
pflag.BoolVarP(&init, "init", "i", false, "creates a new Taskfile.yml in the current folder")
pflag.BoolVarP(&list, "list", "l", false, "lists tasks of current Taskfile")
pflag.BoolVar(&update, "update", false, "selfupdate task")
pflag.StringVarP(&taskfileLocation, "config", "c", "Taskfile.yml", "Specify taskfile location")
pflag.BoolVar(&listHidden, "list-hidden",
false, "lists all tasks")
pflag.BoolVar(&withDeps, "with-deps", false, "list all tasks with dependencies")
Expand Down Expand Up @@ -157,12 +159,13 @@ func main() {
}

e := task.Executor{
Force: force,
Watch: watch,
Verbose: verbose,
Silent: silent,
Dir: dir,
Dry: dry,
Force: force,
Watch: watch,
Verbose: verbose,
Silent: silent,
Dir: dir,
Dry: dry,
TaskfileLocation: taskfileLocation,

Context: ctx,

Expand Down
8 changes: 7 additions & 1 deletion internal/taskfile/read/taskfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ var (
)

// Taskfile reads a Taskfile for a given directory
func Taskfile(dir string) (*taskfile.Taskfile, error) {
func Taskfile(dir, location string) (*taskfile.Taskfile, error) {
path := filepath.Join(dir, "Taskfile.yml")
if location != "" {
path = filepath.Join(dir, location)
}
if location != "" && filepath.IsAbs(location) {
path = location
}
if _, err := os.Stat(path); err != nil {
return nil, ErrNoTaskfileFound
}
Expand Down
17 changes: 9 additions & 8 deletions task.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ const (

// Executor executes a Taskfile
type Executor struct {
Taskfile *taskfile.Taskfile
Dir string
Force bool
Watch bool
Verbose bool
Silent bool
Dry bool
Taskfile *taskfile.Taskfile
Dir string
Force bool
Watch bool
Verbose bool
Silent bool
Dry bool
TaskfileLocation string

Context context.Context

Expand Down Expand Up @@ -78,7 +79,7 @@ func (e *Executor) Run(calls ...taskfile.Call) error {
// Setup setups Executor's internal state
func (e *Executor) Setup() error {
var err error
e.Taskfile, err = read.Taskfile(e.Dir)
e.Taskfile, err = read.Taskfile(e.Dir, e.TaskfileLocation)
if err != nil {
return err
}
Expand Down

0 comments on commit 52de065

Please sign in to comment.