class TheFox::Timr::Command::TaskCommand

Man page: timr-task(1)

Constants

MAN_PATH

Path to man page.

Public Class Methods

new(argv = Array.new) click to toggle source
Calls superclass method TheFox::Timr::Command::BasicCommand.new
# File lib/timr/command/task_command.rb, line 22
def initialize(argv = Array.new)
    super()
    # puts "argv #{argv}"
    
    @help_opt = false
    @show_opt = false
    @add_opt = false
    @remove_opt = false
    @set_opt = false
    
    @verbose_opt = false
    @tracks_opt = false
    
    @foreign_id_opt = nil
    @unset_foreign_id_opt = nil
    @name_opt = nil
    @description_opt = nil
    @estimation_opt = nil
    @billed_opt = nil
    @unbilled_opt = nil
    
    @hourly_rate_opt = nil
    @unset_hourly_rate_opt = nil
    @has_flat_rate_opt = nil
    @unset_flat_rate_opt = nil
    
    # Holds Task instances.
    @tasks_opt = Set.new
    
    loop_c = 0 # Limit the loop.
    while loop_c < 1024 && argv.length > 0
        loop_c += 1
        arg = argv.shift
        
        case arg
        when '-h', '--help'
            @help_opt = true
        
        when '-v', '--verbose'
            @verbose_opt = true
        when '-t', '--tracks'
            @tracks_opt = true
        
        when '--id'
            @foreign_id_opt = argv.shift.strip
        when '--no-id'
            @unset_foreign_id_opt = true
        when '-n', '--name'
            @name_opt = argv.shift
        when '--desc', '--description', '-d' # -d not official
            @description_opt = argv.shift
        when '-e', '--est', '--estimation'
            @estimation_opt = argv.shift
            # puts "est: #{@estimation_opt}"
        when '-b', '--billed'
            @billed_opt = true
        when '--unbilled'
            @unbilled_opt = true
        
        when '-r', '--hourly-rate'
            @hourly_rate_opt = argv.shift
        when '--no-hourly-rate'
            @unset_hourly_rate_opt = true
        when '--fr', '--flat', '--flat-rate'
            @has_flat_rate_opt = true
        when '--no-flat', '--no-flat-rate'
            @unset_flat_rate_opt = true
        
        when 'show'
            @show_opt = true
        when 'add'
            @add_opt = true
        when 'remove'
            @remove_opt = true
        when 'set'
            @set_opt = true
        
        when Task
            @tasks_opt << arg
        else
            @tasks_opt << arg
        end
        
        # puts "argv #{argv}"
    end
    
    if @foreign_id_opt && @unset_foreign_id_opt
        raise TaskCommandError, 'Cannot use --id and --no-id.'
    end
    if @billed_opt && @unbilled_opt
        raise TaskCommandError, 'Cannot use --billed and --unbilled.'
    end
    if !@hourly_rate_opt.nil? && @unset_hourly_rate_opt
        raise TaskCommandError, 'Cannot use --hourly-rate and --no-hourly-rate.'
    end
    if @has_flat_rate_opt && @unset_flat_rate_opt
        raise TaskCommandError, 'Cannot use --flat-rate and --no-flat-rate.'
    end
end

Public Instance Methods

run() click to toggle source

See TheFox::Timr::Command::BasicCommand#run.

# File lib/timr/command/task_command.rb, line 123
def run
    if @help_opt
        help
        return
    end
    
    @timr = Timr.new(@cwd)
    
    if @add_opt
        run_add
    elsif @remove_opt
        run_remove
    elsif @set_opt
        run_set
    else
        if @tasks_opt.count == 0
            run_show_all
        else
            run_show
        end
    end
end