class TheFox::Timr::Command::StopCommand

Stop the current running Track.

Man page: timr-stop(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/stop_command.rb, line 17
def initialize(argv = Array.new)
    super()
    
    @help_opt = false
    
    @start_date_opt = nil
    @start_time_opt = nil
    @end_date_opt = nil
    @end_time_opt = nil
    
    @message_opt = nil
    @edit_opt = false
    
    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 '--sd', '--start-date'
            @start_date_opt = argv.shift
        when '--st', '--start-time'
            @start_time_opt = argv.shift
        
        when '--ed', '--end-date', '-d', '--date'
            @end_date_opt = argv.shift
        when '--et', '--end-time', '-t', '--time'
            @end_time_opt = argv.shift
        
        when '-m', '--message'
            @message_opt = argv.shift
        when '--edit'
            @edit_opt = true
        else
            raise StopCommandError, "Unknown argument '#{arg}'. See 'timr stop --help'."
        end
    end
end

Public Instance Methods

run() click to toggle source

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

# File lib/timr/command/stop_command.rb, line 60
def run
    if @help_opt
        help
        return
    end
    
    @timr = Timr.new(@cwd)
    
    track = @timr.stack.current_track
    if track
        task = track.task
        if task
            run_edit(task.id, track.id)
        end
    end
    
    options = {
        :start_date => @start_date_opt,
        :start_time => @start_time_opt,
        
        :end_date => @end_date_opt,
        :end_time => @end_time_opt,
        
        :message => @message_opt,
    }
    
    track = @timr.stop(options)
    unless track
        puts 'No running Track to stop.'
        return
    end
    
    puts track.to_compact_str
    puts @timr.stack
end