Sha256: 6c0e6ec444878a0af8bbe36797e3fd762c5c500883777b8090d7fcd60a664e57

Contents?: true

Size: 1.8 KB

Versions: 35

Compression:

Stored size: 1.8 KB

Contents

# frozen_string_literal: true

require_relative 'base_subcommand'
require_relative '../models/entry_group'
require_relative '../views/entry_group/show'

module Dsu
  module Subcommands
    class Edit < BaseSubcommand
      # TODO: I18n.
      map %w[d] => :date
      map %w[n] => :today
      map %w[t] => :tomorrow
      map %w[y] => :yesterday

      desc I18n.t('subcommands.edit.date.desc'), I18n.t('subcommands.edit.date.usage')
      long_desc I18n.t('subcommands.edit.date.long_desc', date_option_description: date_option_description)
      def date(date)
        entry_group = Models::EntryGroup.edit(time: Time.parse(date))
        Views::EntryGroup::Show.new(entry_group: entry_group).render
      rescue ArgumentError => e
        puts apply_theme(I18n.t('errors.error', message: e.message), theme_color: color_theme.error)
        exit 1
      end

      desc I18n.t('subcommands.edit.today.desc'), I18n.t('subcommands.edit.today.usage')
      long_desc I18n.t('subcommands.edit.today.long_desc')
      def today
        entry_group = Models::EntryGroup.edit(time: Time.now)
        Views::EntryGroup::Show.new(entry_group: entry_group).render
      end

      desc I18n.t('subcommands.edit.tomorrow.desc'), I18n.t('subcommands.edit.tomorrow.usage')
      long_desc I18n.t('subcommands.edit.tomorrow.long_desc')
      def tomorrow
        entry_group = Models::EntryGroup.edit(time: Time.now.tomorrow)
        Views::EntryGroup::Show.new(entry_group: entry_group).render
      end

      desc I18n.t('subcommands.edit.yesterday.desc'), I18n.t('subcommands.edit.yesterday.usage')
      long_desc I18n.t('subcommands.edit.yesterday.long_desc')
      def yesterday
        entry_group = Models::EntryGroup.edit(time: Time.now.yesterday)
        Views::EntryGroup::Show.new(entry_group: entry_group).render
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
dsu-3.0.5 lib/dsu/subcommands/edit.rb
dsu-3.0.4 lib/dsu/subcommands/edit.rb
dsu-3.0.3 lib/dsu/subcommands/edit.rb
dsu-3.0.1 lib/dsu/subcommands/edit.rb
dsu-3.0.0 lib/dsu/subcommands/edit.rb
dsu-3.0.0.beta.3 lib/dsu/subcommands/edit.rb
dsu-3.0.0.beta.2 lib/dsu/subcommands/edit.rb
dsu-3.0.0.beta.1 lib/dsu/subcommands/edit.rb
dsu-3.0.0.beta.0 lib/dsu/subcommands/edit.rb
dsu-3.0.0.alpha.12 lib/dsu/subcommands/edit.rb
dsu-3.0.0.alpha.11 lib/dsu/subcommands/edit.rb
dsu-3.0.0.alpha.10 lib/dsu/subcommands/edit.rb
dsu-3.0.0.alpha.9 lib/dsu/subcommands/edit.rb
dsu-3.0.0.alpha.8 lib/dsu/subcommands/edit.rb
dsu-3.0.0.alpha.7 lib/dsu/subcommands/edit.rb
dsu-3.0.0.alpha.6 lib/dsu/subcommands/edit.rb
dsu-3.0.0.alpha.5 lib/dsu/subcommands/edit.rb
dsu-3.0.0.alpha.4 lib/dsu/subcommands/edit.rb
dsu-3.0.0.alpha.3 lib/dsu/subcommands/edit.rb
dsu-3.0.0.alpha.2 lib/dsu/subcommands/edit.rb