Skip to content

Commit 9fba7c7

Browse files
authored
Add dry run mode, Fixes #9 (#71)
1 parent fc27f71 commit 9fba7c7

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

cmd/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
type mykeOpts struct {
1515
Verbose []bool `short:"v" long:"verbose" description:"show verbose logs"`
1616
File string `short:"f" long:"file" description:"yml file to load" default:"myke.yml"`
17+
DryRun bool `short:"n" long:"dry-run" description:"print tasks without running them"`
1718
Version bool `long:"version" description:"print myke version"`
1819
Template string `long:"template" description:"template file to render"`
1920
License bool `long:"license" description:"show open source licenses"`

cmd/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func Run(opts *mykeOpts, tasks []string) error {
1414

1515
w := loadWorkspace(opts.File)
1616
for _, q := range queries {
17-
err := core.ExecuteQuery(&w, q)
17+
err := core.ExecuteQuery(&w, q, opts.DryRun)
1818
if err != nil {
1919
return errors.Wrap(err, "error running command")
2020
}

core/execution.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ type Execution struct {
1616
Query *Query
1717
Project *Project
1818
Task *Task
19+
DryRun bool
1920
}
2021

2122
// ExecuteQuery executes the given query in the workspace
22-
func ExecuteQuery(w *Workspace, q Query) error {
23+
func ExecuteQuery(w *Workspace, q Query, dryRun bool) error {
2324
matches := q.search(w)
2425
if len(matches) == 0 {
2526
return errors.New("no task matched: " + q.Raw)
@@ -30,6 +31,7 @@ func ExecuteQuery(w *Workspace, q Query) error {
3031
Query: &q,
3132
Project: &match.Project,
3233
Task: &match.Task,
34+
DryRun: dryRun,
3335
}
3436
err := e.Execute()
3537
if err != nil {
@@ -43,6 +45,10 @@ func ExecuteQuery(w *Workspace, q Query) error {
4345
func (e *Execution) Execute() error {
4446
start := time.Now()
4547
displayName := e.Project.Name + "/" + e.Task.Name
48+
if e.DryRun {
49+
log.Infof("%v: Will run", displayName)
50+
return nil
51+
}
4652
log.Infof("%v: Running", displayName)
4753

4854
err := retry(func(attempt int) (bool, error) {

examples/tag/package_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import (
66
)
77

88
var tests = []TestTable{
9+
{`tag`, `tag`, `tags1/tag`},
10+
{`tag`, `tag`, `tags2/tag`},
11+
{`tag`, `--dry-run tag`, `(?s)tags1/tag: Will run.*tags2/tag: Will run`},
912
{`tagA/tag`, `tagA/tag`, `tags1 tag`},
1013
{`tagA/tag`, `tagA/tag`, `(tags2){0}`},
1114
{`tagB/tag`, `tagB/tag`, `tags1/tag`},

0 commit comments

Comments
 (0)