Sha256: 959581d17d9bb4c5a19d6fe04210df4e448dc389ab0f8293429c466d8e9b195e

Contents?: true

Size: 1.46 KB

Versions: 3

Compression:

Stored size: 1.46 KB

Contents

require 'clamp'
require 'tty-table'
require 'tty-prompt'

require "bullit/version"
require "bullit/file"

module BulletJournal
  class Error < StandardError; end
  
  Clamp do
    option "--loud", :flag, "say it loud"

    subcommand "generate", "generator functions" do
      subcommand "today", "creates task file for today" do
        def execute
          BulletJournal::File.generate_today_file(loud?)
        end
      end
    end

    subcommand "tasks", "manage today's tasks" do
      subcommand "list", "list your tasks" do
        def execute
          show_tasks
        end
      end

      subcommand "add", "add a task" do
        option "--text", "TEXT", "what the task is"
        def execute
          prompt = TTY::Prompt.new
          text = prompt.ask('what do you need to do?') if text.nil?
          BulletJournal::File.add_task(text)
          show_tasks
        end
      end

      subcommand "complete", "complete a task" do
        parameter "TASK_NUMBER", "what the task is", required: true
        def execute
          BulletJournal::File.complete_task(task_number.to_i)
          show_tasks
        end
      end
    end

    def show_tasks
      if tasks = BulletJournal::File.today_tasks
        tasks = tasks.each_with_index.map{ |t,i| [i,t[:text], t[:complete] == true ? ' ✅' : ' ❌']}

        puts TTY::Table.new(['#', 'Task', ''], tasks).render(:unicode)
      elsif tasks == {}
        puts "There's no tasks for today"
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bullit-0.1.2p1 lib/bullit.rb
bullit-0.1.2 lib/bullit.rb
bullit-0.1.1 lib/bullit.rb