Sha256: 34933b38f297d261fcaf56ef33215dc03f24f5b3ecd5a0ac5575db41da1e822b

Contents?: true

Size: 1.85 KB

Versions: 5

Compression:

Stored size: 1.85 KB

Contents

# frozen_string_literal: true

require_relative '../base_cli'

module Dsu
  module Subcommands
    class List < Dsu::BaseCLI
      map %w[d] => :date
      map %w[n] => :today
      map %w[t] => :tomorrow
      map %w[y] => :yesterday

      desc 'today, n',
        'Displays the DSU entries for today'
      long_desc <<-LONG_DESC
        Displays the DSU entries for today. This command has no options.
      LONG_DESC
      def today
        time = Time.now
        sorted_dsu_times_for(times: [time, time.yesterday]).each do |t|
          view_entry_group(time: t)
          puts
        end
      end

      desc 'tomorrow, t',
        'Displays the DSU entries for tomorrow'
      long_desc <<-LONG_DESC
        Displays the DSU entries for tomorrow. This command has no options.
      LONG_DESC
      def tomorrow
        time = Time.now
        sorted_dsu_times_for(times: [time.tomorrow, time]).each do |t|
          view_entry_group(time: t)
          puts
        end
      end

      desc 'yesterday, y',
        'Displays the DSU entries for yesterday'
      long_desc <<-LONG_DESC
        Displays the DSU entries for yesterday. This command has no options.
      LONG_DESC
      def yesterday
        time = Time.now
        sorted_dsu_times_for(times: [time.yesterday, time.yesterday.yesterday]).each do |t|
          view_entry_group(time: t)
          puts
        end
      end

      desc 'date, d DATE',
        'Displays the DSU entries for DATE'
      long_desc <<-LONG_DESC
      Displays the DSU entries for DATE.
        \x5 #{date_option_description}
      LONG_DESC
      def date(date)
        time = Time.parse(date)
        sorted_dsu_times_for(times: [time, time.yesterday]).each do |t|
          view_entry_group(time: t)
          puts
        end
      rescue ArgumentError => e
        say "Error: #{e.message}", ERROR
        exit 1
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
dsu-1.0.0 lib/dsu/subcommands/list.rb
dsu-0.1.0.alpha.5 lib/dsu/subcommands/list.rb
dsu-0.1.0.alpha.4 lib/dsu/subcommands/list.rb
dsu-0.1.0.alpha.3 lib/dsu/subcommands/list.rb
dsu-0.1.0.alpha.2 lib/dsu/subcommands/list.rb