Sha256: 9a32560d6a9ad5ef253f8d7644d8a4ef94ba81d73fc4c16a240c15bc6f0f1487

Contents?: true

Size: 762 Bytes

Versions: 2

Compression:

Stored size: 762 Bytes

Contents

# frozen_string_literal: true

require 'optparse'
require 'hbtrack/command'
require 'hbtrack/store'

module Hbtrack
  class RemoveCommand < Command
    def initialize(hbt, options)
      super(hbt, options)
    end

    def execute
      return remove(@names) if @names
      super
    end

    def create_option_parser
      OptionParser.new do |opts|
        opts.banner = 'Usage: hbtrack remove [<habit_name>]'
      end
    end

    def remove(names)
      names.each do |name|
        habit = @hbt.find(name) do
          return ErrorHandler.raise_if_habit_error(name)
        end

        @hbt.habits.delete(habit)
      end

      Store.new(@hbt.habits, @hbt.output_file_name).save
      Hbtrack::Util.blue("Remove #{names.join(',')}!")
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hbtrack-0.0.7 lib/hbtrack/command/remove_command.rb
hbtrack-0.0.6 lib/hbtrack/command/remove_command.rb