module Commands::Add

Public Class Methods

included(thor) click to toggle source
# File lib/commands/add.rb, line 3
def self.included(thor)
    thor.class_eval do
                option :tag, :type => :string, :alias => '-t', default: ""
                option :estimate, :type => :string, :alias => '-e', default: false
                option :start, :type => :boolean, default: true
                desc "add [NAME]", "Create new log"
                def add(name)
                        log = Log.new(name: name).tag(options[:tag])

                        # estimate option
                        if options[:estimate]
                                estimation = ChronicDuration.parse(options[:estimate]) if !estimation
                                if !estimation
                                        output do
                                                say "could not parse estimation time: " + options[:estimate], :red
                                        end
                                        exit
                                end
                                log.estimation = estimation
                        end

                        # save log
                        if !log.save
                                log.errors.full_messages.each do |error|
                                        output do
                                                say error, :red
                                        end
                                end
                                exit
                        end

                        # start option
                        if options[:start] and log.start!
                                output do
                                        say name.to_s + " added and started", :green
                                end
                        else
                                output do
                                        say name.to_s + " added", :green
                                end
                        end
                end
        end
end

Public Instance Methods

add(name) click to toggle source
# File lib/commands/add.rb, line 9
def add(name)
        log = Log.new(name: name).tag(options[:tag])

        # estimate option
        if options[:estimate]
                estimation = ChronicDuration.parse(options[:estimate]) if !estimation
                if !estimation
                        output do
                                say "could not parse estimation time: " + options[:estimate], :red
                        end
                        exit
                end
                log.estimation = estimation
        end

        # save log
        if !log.save
                log.errors.full_messages.each do |error|
                        output do
                                say error, :red
                        end
                end
                exit
        end

        # start option
        if options[:start] and log.start!
                output do
                        say name.to_s + " added and started", :green
                end
        else
                output do
                        say name.to_s + " added", :green
                end
        end
end