Skip to content

Commit de9d3bc

Browse files
committed
More attempts to fix CI
1 parent 75cc00a commit de9d3bc

File tree

1 file changed

+33
-7
lines changed

1 file changed

+33
-7
lines changed

lib/syntax_tree/cli.rb

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,15 @@ def handler
5151
def source
5252
handler.read(filepath)
5353
end
54+
55+
def writable?
56+
File.writable?(filepath)
57+
end
5458
end
5559

5660
# An item of work that corresponds to a script content passed via the
5761
# command line.
5862
class ScriptItem
59-
FILEPATH = :script
60-
6163
attr_reader :source
6264

6365
def initialize(source)
@@ -69,7 +71,30 @@ def handler
6971
end
7072

7173
def filepath
72-
FILEPATH
74+
:script
75+
end
76+
77+
def writable?
78+
false
79+
end
80+
end
81+
82+
# An item of work that correspond to the content passed in via stdin.
83+
class STDINItem
84+
def handler
85+
HANDLERS[".rb"]
86+
end
87+
88+
def filepath
89+
:stdin
90+
end
91+
92+
def source
93+
$stdin.read
94+
end
95+
96+
def writable?
97+
false
7398
end
7499
end
75100

@@ -196,7 +221,7 @@ def run(item)
196221

197222
source = item.source
198223
formatted = item.handler.format(source, options.print_width)
199-
File.write(filepath, formatted) if item.filepath != :script
224+
File.write(filepath, formatted) if item.writable?
200225

201226
color = source == formatted ? Color.gray(filepath) : filepath
202227
delta = ((Time.now - start) * 1000).round
@@ -386,7 +411,7 @@ def run(argv)
386411
return 1
387412
end
388413

389-
# If we're not reading from stdin and the user didn't supply and
414+
# If we're not reading from stdin and the user didn't supply any
390415
# filepaths to be read, then we exit with the usage message.
391416
if $stdin.tty? && arguments.empty? && options.scripts.empty?
392417
warn(HELP)
@@ -403,12 +428,13 @@ def run(argv)
403428
Dir
404429
.glob(pattern)
405430
.each do |filepath|
406-
queue << FileItem.new(filepath) if File.file?(filepath)
431+
queue << FileItem.new(filepath) if File.readable?(filepath)
407432
end
408433
end
434+
409435
options.scripts.each { |script| queue << ScriptItem.new(script) }
410436
else
411-
queue << ScriptItem.new($stdin.read)
437+
queue << STDINItem.new
412438
end
413439

414440
# At the end, we're going to return whether or not this worker ever

0 commit comments

Comments
 (0)