Skip to content

Commit 5b34b72

Browse files
committed
Print task's directory taking into account any dir attributes.
1 parent 31c068a commit 5b34b72

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

runx.rb

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
require 'pathname'
22

33
class Task
4-
def initialize(name, doc, block, dir, auto)
4+
def initialize(name, block, doc, dir, auto)
55
@name = name
6-
@doc = doc
76
@block = block
7+
@doc = doc
88
@dir = dir
99
@auto = auto
1010
end
1111

1212
def run(manager, *args)
1313
raise DirNotFoundError.new(@dir, self) if !File.exist?(@dir)
1414
Dir.chdir(@dir) do
15+
$stderr.puts "[runx] In #{@dir}."
1516
@block.call(*args)
1617
end
1718
end
@@ -113,10 +114,7 @@ def task_defined?(name)
113114

114115
def run_task(name, *args)
115116
task = @tasks[name.to_s.downcase]
116-
if task.nil?
117-
raise TaskNotFoundError.new(name)
118-
end
119-
117+
raise TaskNotFoundError.new(name) if task.nil?
120118
task.run(self, *args)
121119
end
122120

@@ -181,7 +179,7 @@ def run(*args, &block)
181179
raise DuplicateTaskError.new(name)
182180
end
183181

184-
task = Task.new(name.to_s, @doc, block, @task_dir || @root_dir, @auto)
182+
task = Task.new(name.to_s, block, @doc, @task_dir || @root_dir, @auto)
185183
@tasks[key] = task
186184

187185
if @auto
@@ -263,15 +261,13 @@ def find_runfile
263261
manager = TaskManager.new
264262
manager.load(runfile)
265263

266-
dir = File.dirname(runfile)
267-
$stderr.puts "[runx] In #{dir}."
268-
269264
task_name = ARGV[0] || manager.auto_task
270265

271266
is_help = ['-h', '--help', 'help'].include?(task_name)
272267
show_help = !task_name || (is_help && !manager.task_defined?(task_name))
273268

274269
if show_help
270+
$stderr.puts "[runx] In #{File.dirname(runfile)}."
275271
$stderr.puts
276272
manager.show_help
277273
else

0 commit comments

Comments
 (0)