@@ -6,8 +6,6 @@ module SyntaxTree
66 # Syntax Tree ships with the `stree` CLI, which can be used to inspect and
77 # manipulate Ruby code. This module is responsible for powering that CLI.
88 module CLI
9- CONFIG_FILE = ".streerc"
10-
119 # A utility wrapper around colored strings in the output.
1210 class Color
1311 attr_reader :value , :code
@@ -289,16 +287,41 @@ def parser
289287 end
290288 end
291289
290+ # We allow a minimal configuration file to act as additional command line
291+ # arguments to the CLI. Each line of the config file should be a new
292+ # argument, as in:
293+ #
294+ # --plugins=plugin/single_quote
295+ # --print-width=100
296+ #
297+ # When invoking the CLI, we will read this config file and then parse it if
298+ # it exists in the current working directory.
299+ class ConfigFile
300+ FILENAME = ".streerc"
301+
302+ attr_reader :filepath
303+
304+ def initialize
305+ @filepath = File . join ( Dir . pwd , FILENAME )
306+ end
307+
308+ def exists?
309+ File . readable? ( filepath )
310+ end
311+
312+ def arguments
313+ exists? ? File . readlines ( filepath , chomp : true ) : [ ]
314+ end
315+ end
316+
292317 class << self
293318 # Run the CLI over the given array of strings that make up the arguments
294319 # passed to the invocation.
295320 def run ( argv )
296321 name , *arguments = argv
297322
298- config_file = File . join ( Dir . pwd , CONFIG_FILE )
299- if File . readable? ( config_file )
300- arguments . unshift ( *File . readlines ( config_file , chomp : true ) )
301- end
323+ config_file = ConfigFile . new
324+ arguments . unshift ( *config_file . arguments )
302325
303326 options = Options . new
304327 options . parse ( arguments )
0 commit comments