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

Skip tasks v0.4.0 #16

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ To see a list of all available tasks with their descriptions:
$ crystal sam.cr help
```

To skip a task or prerequisite task:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's maybe make it a bit more clear:

To skip a task or prerequisite task specify it's path with "~" prefix


```shell
$ crystal sam.cr name ~prereq2
```

#### Tasks with arguments

To pass arguments to your task just list them after it's name:
Expand Down
6 changes: 6 additions & 0 deletions spec/sam_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ describe Sam do
Container.tasks.should eq(["db:schema", "db:with_argument"])
end
end
context "with arguments" do
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add an empty line between blocks

it "ignores dependencies that have a ~" do
Sam.process_tasks(["db:schema:2", "~db:schema:1", "f2=2"])
Container.tasks.should eq(["db:db:migrate"])
end
end
end
end

Expand Down
3 changes: 3 additions & 0 deletions spec/spec_helper.cr
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ namespace "db" do
puts "1"
Container.add("db:schema:1")
end

task "2", ["1", "db:db:migrate"] do |t, args|
end
end

task "with_argument" do |t, args|
Expand Down
1 change: 1 addition & 0 deletions src/sam/task.cr
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ module Sam

# Launch current task. Prerequisites are invoked first.
def call(args : Args)
return if args.raw.find {|x| "~#{path}" == x }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's grep all tasks that need to be skipped in Args class constructor into @ignore_tasks variable (and remove ~ from the beginning). This way #raw doesn't include any Sam arguments and here we can do args.ignore_tasks.include?(path)

P.S. Also add an empty line after guard clause

@invoked = true
case @block.arity
when 0, 1
Expand Down