Class: Bouch::CLI
- Inherits:
-
Object
- Object
- Bouch::CLI
- Defined in:
- lib/bouch/cli.rb
Overview
Parse the command line
Instance Attribute Summary collapse
-
#yaml_file ⇒ Object
Returns the value of attribute yaml_file.
Instance Method Summary collapse
-
#initialize(file) ⇒ CLI
constructor
A new instance of CLI.
- #start ⇒ Object
- #usage ⇒ Object
Constructor Details
#initialize(file) ⇒ CLI
Returns a new instance of CLI.
13 14 15 |
# File 'lib/bouch/cli.rb', line 13 def initialize(file) @yaml_file = file end |
Instance Attribute Details
#yaml_file ⇒ Object
Returns the value of attribute yaml_file.
11 12 13 |
# File 'lib/bouch/cli.rb', line 11 def yaml_file @yaml_file end |
Instance Method Details
#start ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/bouch/cli.rb', line 17 def start if @yaml_file.nil? || %w[--help -h].include?(@yaml_file) usage elsif %w[--version -v].include?(@yaml_file) puts Paint["bouch #{Bouch::VERSION}", :magenta, :bold] elsif @yaml_file == 'example' puts Bouch::EXAMPLE_POUCH elsif File.exist?(@yaml_file) begin budget = Bouch.new(@yaml_file) budget.show_budget rescue ArgumentError, Psych::SyntaxError => e puts Paint["Whoops. Failed to load the budget pouch file: #{e.}", :red] usage exit 1 end else puts Paint["Whoops. The budget pouch file specified: #{@yaml_file} ; does not exist!", :red] usage exit 1 end end |
#usage ⇒ Object
40 41 42 43 44 45 |
# File 'lib/bouch/cli.rb', line 40 def usage puts Paint["<<bouch #{Bouch::VERSION}>>", :magenta, :bold] puts "Usage: #{Paint[File.basename($PROGRAM_NAME), :green]} #{Paint['[YAML_FILE]', :faint]}" puts " #{Paint[File.basename($PROGRAM_NAME), :green]} #{Paint['example', :magenta]} # Print an example budget pouch YAML" puts " #{Paint[File.basename($PROGRAM_NAME), :green]} #{Paint['--version', :magenta]} # Print version" end |