@@ -63,12 +63,13 @@ def writable?
63
63
class ScriptItem
64
64
attr_reader :source
65
65
66
- def initialize ( source )
66
+ def initialize ( source , handler_extension )
67
67
@source = source
68
+ @handler_extension = handler_extension
68
69
end
69
70
70
71
def handler
71
- HANDLERS [ ".rb" ]
72
+ HANDLERS [ @handler_extension ]
72
73
end
73
74
74
75
def filepath
@@ -82,8 +83,12 @@ def writable?
82
83
83
84
# An item of work that correspond to the content passed in via stdin.
84
85
class STDINItem
86
+ def initialize ( handler_extension )
87
+ @handler_extension = handler_extension
88
+ end
89
+
85
90
def handler
86
- HANDLERS [ ".rb" ]
91
+ HANDLERS [ @handler_extension ]
87
92
end
88
93
89
94
def filepath
@@ -457,7 +462,10 @@ def run(item)
457
462
The maximum line width to use when formatting.
458
463
459
464
-e SCRIPT
460
- Parse an inline Ruby string.
465
+ Parse an inline string.
466
+
467
+ --handler=EXTENSION
468
+ A file extension matching the content passed in via STDIN or -e. Defaults to 'rb'
461
469
HELP
462
470
463
471
# This represents all of the options that can be passed to the CLI. It is
@@ -468,13 +476,15 @@ class Options
468
476
:plugins ,
469
477
:print_width ,
470
478
:scripts ,
479
+ :handler_extension ,
471
480
:target_ruby_version
472
481
473
482
def initialize
474
483
@ignore_files = [ ]
475
484
@plugins = [ ]
476
485
@print_width = DEFAULT_PRINT_WIDTH
477
486
@scripts = [ ]
487
+ @handler_extension = ".rb"
478
488
@target_ruby_version = DEFAULT_RUBY_VERSION
479
489
end
480
490
@@ -523,6 +533,13 @@ def parser
523
533
# it and add it to the list of scripts to run.
524
534
opts . on ( "-e SCRIPT" ) { |script | @scripts << script }
525
535
536
+ # If there is a handler specified, then parse it and use it for
537
+ # STDIN and scripts.
538
+ opts . on ( "--handler=EXTENSION" ) do |extension |
539
+ # Both ".rb" and "rb" are going to work
540
+ @handler_extension = ".#{ extension . delete_prefix ( "." ) } "
541
+ end
542
+
526
543
# If there is a target ruby version specified on the command line,
527
544
# parse that out and use it when formatting.
528
545
opts . on ( "--target-ruby-version=VERSION" ) do |version |
@@ -630,9 +647,11 @@ def run(argv)
630
647
end
631
648
end
632
649
633
- options . scripts . each { |script | queue << ScriptItem . new ( script ) }
650
+ options . scripts . each do |script |
651
+ queue << ScriptItem . new ( script , options . handler_extension )
652
+ end
634
653
else
635
- queue << STDINItem . new
654
+ queue << STDINItem . new ( options . handler_extension )
636
655
end
637
656
638
657
# At the end, we're going to return whether or not this worker ever
0 commit comments