Class: SyntaxTree::CLI::ConfigFile
- Inherits:
-
Object
- Object
- SyntaxTree::CLI::ConfigFile
- Defined in:
- lib/syntax_tree/cli.rb
Overview
We allow a minimal configuration file to act as additional command line arguments to the CLI. Each line of the config file should be a new argument, as in:
--plugins=plugin/single_quote
--print-width=100
When invoking the CLI, we will read this config file and then parse it if it exists in the current working directory.
Constant Summary collapse
- FILENAME =
".streerc"
Instance Attribute Summary collapse
-
#filepath ⇒ Object
readonly
Returns the value of attribute filepath.
Instance Method Summary collapse
- #arguments ⇒ Object
- #exists? ⇒ Boolean
-
#initialize(filepath = nil) ⇒ ConfigFile
constructor
A new instance of ConfigFile.
Constructor Details
#initialize(filepath = nil) ⇒ ConfigFile
Returns a new instance of ConfigFile.
575 576 577 578 579 580 581 582 583 584 585 |
# File 'lib/syntax_tree/cli.rb', line 575 def initialize(filepath = nil) if filepath if File.readable?(filepath) @filepath = filepath else raise ArgumentError, "Invalid configuration file: #{filepath}" end else @filepath = File.join(Dir.pwd, FILENAME) end end |
Instance Attribute Details
#filepath ⇒ Object (readonly)
Returns the value of attribute filepath.
573 574 575 |
# File 'lib/syntax_tree/cli.rb', line 573 def filepath @filepath end |
Instance Method Details
#arguments ⇒ Object
591 592 593 |
# File 'lib/syntax_tree/cli.rb', line 591 def arguments exists? ? File.readlines(filepath, chomp: true) : [] end |
#exists? ⇒ Boolean
587 588 589 |
# File 'lib/syntax_tree/cli.rb', line 587 def exists? File.readable?(filepath) end |