@@ -455,17 +455,26 @@ def run(item)
455
455
#{ Color . bold ( "stree write [--plugins=...] [--print-width=NUMBER] [-e SCRIPT] FILE" ) }
456
456
Read, format, and write back the source of the given files
457
457
458
+ --ignore-files=...
459
+ A glob pattern to ignore files when processing. This can be specified
460
+ multiple times to ignore multiple patterns.
461
+
458
462
--plugins=...
459
463
A comma-separated list of plugins to load.
460
464
461
- --print-width=NUMBER
465
+ --print-width=...
462
466
The maximum line width to use when formatting.
463
467
464
- -e SCRIPT
468
+ -e ...
465
469
Parse an inline string.
466
470
467
- --extension=EXTENSION
468
- A file extension matching the content passed in via STDIN or -e. Defaults to 'rb'
471
+ --extension=...
472
+ A file extension matching the content passed in via STDIN or -e.
473
+ Defaults to '.rb'.
474
+
475
+ --config=...
476
+ Path to a configuration file. Defaults to .streerc in the current
477
+ working directory.
469
478
HELP
470
479
471
480
# This represents all of the options that can be passed to the CLI. It is
@@ -563,8 +572,16 @@ class ConfigFile
563
572
564
573
attr_reader :filepath
565
574
566
- def initialize
567
- @filepath = File . join ( Dir . pwd , FILENAME )
575
+ def initialize ( filepath = nil )
576
+ if filepath
577
+ if File . readable? ( filepath )
578
+ @filepath = filepath
579
+ else
580
+ raise ArgumentError , "Invalid configuration file: #{ filepath } "
581
+ end
582
+ else
583
+ @filepath = File . join ( Dir . pwd , FILENAME )
584
+ end
568
585
end
569
586
570
587
def exists?
@@ -582,8 +599,24 @@ class << self
582
599
def run ( argv )
583
600
name , *arguments = argv
584
601
585
- config_file = ConfigFile . new
586
- arguments . unshift ( *config_file . arguments )
602
+ # First, we need to check if there's a --config option specified
603
+ # so we can use the custom config file path.
604
+ config_filepath = nil
605
+ arguments . each_with_index do |arg , index |
606
+ if arg . start_with? ( "--config=" )
607
+ config_filepath = arg . split ( "=" , 2 ) [ 1 ]
608
+ arguments . delete_at ( index )
609
+ break
610
+ elsif arg == "--config" && arguments [ index + 1 ]
611
+ config_filepath = arguments [ index + 1 ]
612
+ arguments . delete_at ( index + 1 )
613
+ arguments . delete_at ( index )
614
+ break
615
+ end
616
+ end
617
+
618
+ config_file = ConfigFile . new ( config_filepath )
619
+ arguments = config_file . arguments . concat ( arguments )
587
620
588
621
options = Options . new
589
622
options . parse ( arguments )
0 commit comments