class Transaction::Options

Public Class Methods

new() click to toggle source
# File lib/transactions/options.rb, line 5
def initialize
  @options = {}
end

Public Instance Methods

commands_help() click to toggle source

Internal: Prints help for commands that are stored in ARGV. Used in help menu.

Returns nothing.

# File lib/transactions/options.rb, line 78
    def commands_help
      <<-COMMANDHELP

      COMMANDS
      --------
      balance [ACCOUNT]..   Prints account balances, limited to ACCOUNTS.
                            'bal' can be used as a shortcut.
      register [ACCOUNT]..  Prints account register, limited to ACCOUNTS.
                            'reg' can be used as a shortcut.
      print                 Prints transactions formatted for export to ledger.
                            Can be limited by date but not ACCOUNT.
      COMMANDHELP
    end
options() click to toggle source

Internal: Parses options for transactions from the command line.

Returns nothing.

# File lib/transactions/options.rb, line 12
def options
  OptionParser.new do |opts|

    opts.banner = "Usage: transactions [options] COMMAND [ARGS] ..."

    opts.on("-f", "--file PATH", "PATH to yaml file to parse") do |x|
      @options[:file] = x
    end

    opts.on("-c", "--current",
            "don't include entries with future dates") do |x|
      @options[:current] = x
    end

    opts.on("-b", "--begin DATE", "set begin date, DATE: YYYY/MM/DD") do |x|
      @options[:begin] = x
    end

    opts.on("-e", "--end DATE", "set end date, DATE: YYYY/MM/DD") do |x|
      @options[:end] = x
    end

    opts.on("-s", "--subtotal", "show sub-totals for balance") do |x|
      @options[:subtotal] = x
    end

    opts.on("-E", "--empty", "show accounts with zero balance") do |x|
      @options[:empty] = x
    end

    opts.on("-S", "--sort ARG", "sort by field, ARG can be date or tran") do |x|
      @options[:sort] = x
    end

    opts.on("-w", "--wide", "print 132 columns wide for register") do |x|
      @options[:wide] = x
    end

    #opts.on("-C", "--cleared", "only include cleared transactions") do |x|
    #  @options[:cleared] = x
    #end

    #opts.on("-U", "--uncleared", "only include uncleared transactions") do |x|
    #  @options[:uncleared] = x
    #end

    opts.on_tail("-h", "--help", "show this help message") do
      puts opts
      abort self.commands_help
    end

    opts.on_tail("-v", "--version", "show version") do
      abort "#{Transaction::VERSION}"
    end

  end.parse!

  @options

end