Skip to content

Commit 0bfc8ac

Browse files
committed
feat(*): code cleanup and simplification
1 parent b9a3329 commit 0bfc8ac

5 files changed

Lines changed: 20 additions & 29 deletions

File tree

src/commands/base.cr

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ module Geode::Commands
111111
exit_program
112112
end
113113

114+
protected def puts : Nil
115+
stdout.puts
116+
end
117+
114118
protected def puts(msg : String) : Nil
115119
stdout.puts msg
116120
end

src/commands/init.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ module Geode::Commands
9292
license = input
9393
end
9494

95-
stdout.puts
95+
puts
9696
write_shard(name, description, author, version, crystal, license)
9797
end
9898

src/commands/install.cr

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ module Geode::Commands
8787
shards = [] of Shard
8888
Dir.each_child("lib") do |child|
8989
next if child.starts_with? '.'
90-
next unless File.exists?(path = Path["lib"] / child / "shard.yml")
91-
shards << Shard.from_yaml File.read path
90+
next unless Shard.exists? child
91+
92+
shards << Shard.load child
9293
rescue YAML::ParseException
9394
warn "Failed to parse shard.yml contents for '#{child}'"
9495
end

src/commands/licenses.cr

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module Geode::Commands
2727
trigram = Trigram.new do |t|
2828
License.licenses.each { |l| t.add l.title }
2929
end
30-
found = Hash(String, Array(License)).new # { [] of License }
30+
found = Hash(String, Array(License)).new
3131

3232
paths.each do |name, arr|
3333
licenses = [] of License
@@ -80,12 +80,11 @@ module Geode::Commands
8080

8181
Dir.each_child("lib") do |child|
8282
next if child.starts_with? '.'
83-
next unless File.exists?(path = Path["lib"] / child / "shard.yml")
83+
next unless Shard.exists? child
8484

85-
shard = Shard.from_yaml File.read path
86-
libs << shard.name
87-
rescue YAML::ParseException
88-
warn "Failed to parse shard.yml contents for '#{child}'"
85+
libs << Shard.load(child).name
86+
rescue Shard::Error
87+
warn "Failed to parse shard.yml for '#{child}'"
8988
end
9089

9190
libs

src/commands/watch.cr

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,21 @@ module Geode::Commands
1515

1616
def run(arguments : Cling::Arguments, options : Cling::Options) : Nil
1717
shard = Shard.load_local
18-
if shard.targets.empty?
19-
error "No targets defined in shard.yml"
20-
exit_program
21-
end
22-
18+
fatal "No targets defined in shard.yml" if shard.targets.empty?
2319
Dir.mkdir_p "bin"
2420

2521
name = arguments.get?("target").try(&.as_s) || shard.targets.first_key
26-
unless target = shard.targets[name]?
27-
error "Unknown target '#{name}'"
28-
exit_program
29-
end
30-
31-
unless target.has_key? "main"
32-
error "Missing 'main' field for target: #{name}"
33-
exit_program
34-
end
22+
fatal "Unknown target '#{name}'" unless target = shard.targets[name]?
23+
fatal "Missing 'main' field for target: #{name}" unless target.has_key? "main"
3524

3625
begin
37-
interval = options.get("interval").as_f
26+
interval = options.get("interval").to_f64
3827
rescue
39-
error "Could not parse interval (must be a number)"
40-
exit_program
28+
fatal "Could not parse interval (must be a number)"
4129
end
4230

4331
unless old_stamps = get_timestamps
44-
error "No Crystal files found to watch"
45-
exit_program
32+
fatal "No Crystal files found to watch"
4633
end
4734

4835
dry = options.has? "dry"
@@ -102,7 +89,7 @@ module Geode::Commands
10289
loop do
10390
break unless count = sig.receive?
10491
if proc.exists?
105-
stdout.puts if pipe
92+
puts if pipe
10693
info "Cancelling build"
10794
proc.terminate
10895
end

0 commit comments

Comments
 (0)