@@ -455,17 +455,26 @@ def run(item)
455455 #{ Color . bold ( "stree write [--plugins=...] [--print-width=NUMBER] [-e SCRIPT] FILE" ) }
456456 Read, format, and write back the source of the given files
457457
458+ --ignore-files=...
459+ A glob pattern to ignore files when processing. This can be specified
460+ multiple times to ignore multiple patterns.
461+
458462 --plugins=...
459463 A comma-separated list of plugins to load.
460464
461- --print-width=NUMBER
465+ --print-width=...
462466 The maximum line width to use when formatting.
463467
464- -e SCRIPT
468+ -e ...
465469 Parse an inline string.
466470
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.
469478 HELP
470479
471480 # This represents all of the options that can be passed to the CLI. It is
@@ -563,8 +572,16 @@ class ConfigFile
563572
564573 attr_reader :filepath
565574
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
568585 end
569586
570587 def exists?
@@ -582,8 +599,24 @@ class << self
582599 def run ( argv )
583600 name , *arguments = argv
584601
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 )
587620
588621 options = Options . new
589622 options . parse ( arguments )
0 commit comments