Skip to content

Commit

Permalink
Merge pull request #17 from imdrasil/feature/add-crystal-1-support
Browse files Browse the repository at this point in the history
Add crystal 1.0.0 support
  • Loading branch information
imdrasil authored Jun 28, 2021
2 parents ebabed7 + 8041ead commit 5608ed7
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 21 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: CI

on:
push:
schedule:
- cron: "0 7 * * 1"

jobs:
test:
strategy:
fail-fast: false

runs-on: ubuntu-latest

env:
TERM: xterm-256color

steps:
- name: Install Crystal
uses: oprypin/install-crystal@v1

- name: Donwload sources
uses: actions/checkout@v2

- name: Check formatting
run: crystal tool format --check

- name: Install dependencies
run: shards install

- name: Run linter
run: ./bin/ameba

- name: Setup environment
run: crystal examples/sam.cr setup

- name: Run specs
run: crystal spec
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Add this to your application's `shard.yml`:
dependencies:
sam:
github: imdrasil/sam.cr
version: 0.4.0
version: 0.4.1
```
After executing `shards install` Sam-file will be added to the root of your project (unless you already have one).
Expand Down
6 changes: 3 additions & 3 deletions shard.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
name: sam
version: 0.4.0
version: 0.4.1

authors:
- Roman Kalnytskyi <moranibaca@gmail.com>

crystal: 0.35.1
crystal: ">= 0.35.1"

license: MIT

development_dependencies:
ameba:
github: crystal-ameba/ameba
version: "= 0.13.0"
version: "= 0.14.3"

scripts:
postinstall: "false | [ -f ../../sam.cr ] && true || cp -i examples/sam.template ../../sam.cr 2>/dev/null"
4 changes: 2 additions & 2 deletions spec/shell_table_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ describe Sam::ShellTable do
namespace = Sam::Namespace.new("name", nil)
Sam::ShellTable.new([
Sam::Task.new(
-> {},
->{},
%w[],
namespace,
"short_name",
"but very long description, such long that it requires multiple lines to be written"
),
Sam::Task.new(
-> {},
->{},
%w[],
namespace,
"very_long_task_name_such_long_that_it_requires_multiple_lines_to_be_written",
Expand Down
20 changes: 10 additions & 10 deletions spec/task_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,21 @@ describe Sam::Task do
it "accepts no arguments" do
count = 0
namespace.task("t1") { count += 1 }
namespace.task("t2") { |t| t.invoke("t1") }.call(empty_args)
namespace.task("t2", &.invoke("t1")).call(empty_args)
count.should eq(1)
end

it "accepts tuple at the end" do
count = 0
namespace.task("t1") { |_, args| count += args[0].as(Int32) }
namespace.task("t2") { |t| t.invoke("t1", 1) }.call(empty_args)
namespace.task("t2", &.invoke("t1", 1)).call(empty_args)
count.should eq(1)
end

it "accepts hash" do
count = 0
namespace.task("t1") { |_, args| count += args["count"].as(Int32) }
namespace.task("t2") { |t| t.invoke("t1", {"count" => 2}) }.call(empty_args)
namespace.task("t2", &.invoke("t1", {"count" => 2})).call(empty_args)
count.should eq(2)
end

Expand All @@ -123,14 +123,14 @@ describe Sam::Task do
it "accepts hash and array" do
count = 0
namespace.task("t1") { |_, args| count += args["count"].as(Int32) + args[0].as(Int32) }
namespace.task("t2") { |t| t.invoke("t1", {"count" => 2}, [1]) }.call(empty_args)
namespace.task("t2", &.invoke("t1", {"count" => 2}, [1])).call(empty_args)
count.should eq(3)
end

it "ignores invoked tasks" do
count = 0
namespace.task("t1") { count += 1 }
namespace.task("t2", ["t1"]) { |t| t.invoke("t1") }.call(empty_args)
namespace.task("t2", ["t1"], &.invoke("t1")).call(empty_args)
count.should eq(1)
end
end
Expand All @@ -139,21 +139,21 @@ describe Sam::Task do
it "accepts no arguments" do
count = 0
namespace.task("t1") { count += 1 }
namespace.task("t2") { |t| t.execute("t1") }.call(empty_args)
namespace.task("t2", &.execute("t1")).call(empty_args)
count.should eq(1)
end

it "accepts tuple at the end" do
count = 0
namespace.task("t1") { |_, args| count += args[0].as(Int32) }
namespace.task("t2") { |t| t.execute("t1", 1) }.call(empty_args)
namespace.task("t2", &.execute("t1", 1)).call(empty_args)
count.should eq(1)
end

it "accepts hash" do
count = 0
namespace.task("t1") { |_, args| count += args["count"].as(Int32) }
namespace.task("t2") { |t| t.execute("t1", {"count" => 2}) }.call(empty_args)
namespace.task("t2", &.execute("t1", {"count" => 2})).call(empty_args)
count.should eq(2)
end

Expand All @@ -167,14 +167,14 @@ describe Sam::Task do
it "accepts hash and array" do
count = 0
namespace.task("t1") { |_, args| count += args["count"].as(Int32) + args[0].as(Int32) }
namespace.task("t2") { |t| t.execute("t1", {"count" => 2}, [1]) }.call(empty_args)
namespace.task("t2", &.execute("t1", {"count" => 2}, [1])).call(empty_args)
count.should eq(3)
end

it "ignores invoked tasks" do
count = 0
namespace.task("t1") { count += 1 }
namespace.task("t2", ["t1"]) { |t| t.execute("t1") }.call(empty_args)
namespace.task("t2", ["t1"], &.execute("t1")).call(empty_args)
count.should eq(2)
end
end
Expand Down
1 change: 0 additions & 1 deletion src/sam/execution.cr
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

require "./exceptions"

module Sam
Expand Down
4 changes: 2 additions & 2 deletions src/sam/shell_table.cr
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ module Sam
[
[
tasks.map(&.path.size).max,
clean_width * min_content_width_ratio
clean_width * min_content_width_ratio,
].max,
clean_width * max_content_width_ration
clean_width * max_content_width_ration,
].min.to_i.as(Int32)
end

Expand Down
5 changes: 4 additions & 1 deletion src/sam/task.cr
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ module Sam
@description || ""
end

# Launch current task. Prerequisites are invoked first.
# Launch current task.
#
# Prerequisites are invoked before target task.
def call(args : Args)
@invoked = true
case @block.arity
Expand All @@ -44,6 +46,7 @@ module Sam
else
raise "Wrong task block arity - #{@block.arity} and maximum is 2."
end

case @block.arity
when 0
@block.as(-> Void).call
Expand Down
2 changes: 1 addition & 1 deletion src/sam/version.cr
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Sam
VERSION = "0.4.0"
VERSION = "0.4.1"
end

0 comments on commit 5608ed7

Please sign in to comment.