Skip to content

Commit e711f60

Browse files
committed
Refactor: pass command kwargs to run
This allows to set configuration in instance variables (local) instead of class variables (global).
1 parent 20b7818 commit e711f60

File tree

9 files changed

+19
-23
lines changed

9 files changed

+19
-23
lines changed

src/commands/check.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ require "../versions"
44
module Shards
55
module Commands
66
class Check < Command
7-
def run(*args)
7+
def run
88
if has_dependencies?
99
locks # ensures that lockfile exists
1010
verify(spec.dependencies)

src/commands/command.cr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ module Shards
2222
@lockfile_path = File.join(@path, LOCK_FILENAME)
2323
end
2424

25-
abstract def run(*args)
25+
abstract def run(*args, **kwargs)
2626

27-
def self.run(path, *args)
28-
new(path).run(*args)
27+
def self.run(path, *args, **kwargs)
28+
new(path).run(*args, **kwargs)
2929
end
3030

3131
def spec

src/commands/init.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ require "ecr/macros"
44
module Shards
55
module Commands
66
class Init < Command
7-
def run(*args)
7+
def run
88
if File.exists?(shard_path)
99
raise Error.new("#{SPEC_FILENAME} already exists")
1010
end

src/commands/install.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module Shards
44
module Commands
55
# OPTIMIZE: avoid updating GIT caches until required
66
class Install < Command
7-
def run(*args)
7+
def run
88
if lockfile?
99
manager.locks = locks
1010
manager.resolve

src/commands/list.cr

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@ require "./command"
33
module Shards
44
module Commands
55
class List < Command
6-
def self.run(path, @@tree = false)
7-
super
8-
end
6+
@tree = false
97

10-
def run(*args)
8+
def run(@tree = false)
119
return unless has_dependencies?
1210
puts "Shards installed:"
1311
list(spec.dependencies)
@@ -27,7 +25,7 @@ module Shards
2725
indent = " " * level
2826
puts "#{indent}* #{_spec.name} (#{_spec.version})"
2927

30-
indent_level = @@tree ? level + 1 : level
28+
indent_level = @tree ? level + 1 : level
3129
list(_spec.dependencies, indent_level)
3230
end
3331
end

src/commands/outdated.cr

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@ require "./command"
33
module Shards
44
module Commands
55
class Outdated < Command
6+
@prereleases = false
7+
68
@up_to_date = true
79
@output = IO::Memory.new
810

9-
def self.run(path, @@prereleases = false)
10-
super
11-
end
12-
13-
def run(*args)
11+
def run(@prereleases = false)
1412
return unless has_dependencies?
1513

1614
if lockfile?
@@ -44,7 +42,7 @@ module Shards
4442
installed = _spec.version
4543

4644
# already the latest version?
47-
latest = Versions.sort(package.available_versions(@@prereleases)).first
45+
latest = Versions.sort(package.available_versions(@prereleases)).first
4846
return if latest == installed
4947

5048
@up_to_date = false
@@ -53,7 +51,7 @@ module Shards
5351
@output << " (installed: " << installed
5452

5553
# is new version matching constraints available?
56-
available = package.matching_versions(@@prereleases).first
54+
available = package.matching_versions(@prereleases).first
5755
unless available == installed
5856
@output << ", available: " << available
5957
end

src/commands/prune.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ require "../helpers/path"
55
module Shards
66
module Commands
77
class Prune < Command
8-
def run(*args)
8+
def run
99
return unless lockfile?
1010

1111
Dir[File.join(Shards.install_path, "*")].each do |path|

src/commands/update.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module Shards
44
module Commands
55
class Update < Command
66
# TODO: only update specified dependencies (ie. load locked versions, but don't enforce them)
7-
def run(*args)
7+
def run
88
manager.resolve
99

1010
install(manager.packages)

src/commands/version.cr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ require "./command"
33
module Shards
44
module Commands
55
class Version < Command
6-
def self.run(path, *args)
6+
def self.run(path)
77
path = lookup_path(path)
8-
new(path).run(*args)
8+
new(path).run
99
end
1010

11-
def run(*args)
11+
def run
1212
puts spec.version
1313
end
1414

0 commit comments

Comments
 (0)