Skip to content

Instantly share code, notes, and snippets.

@aziflaj
Created March 16, 2017 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aziflaj/d4f82aaf05e8293c08ae79f9b30af35b to your computer and use it in GitHub Desktop.
Save aziflaj/d4f82aaf05e8293c08ae79f9b30af35b to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'thor'
# Simple Todo list CLI
class Dolittle < Thor
def initialize(*args)
super
@file = File.open('todolist.dat', 'a+')
end
desc 'list', 'list all tasks'
def list
@file.readlines.each_with_index do |line, index|
puts "#{index + 1} => #{line}"
end
end
desc 'add TASK', 'adds a new task'
def add(task)
@file.puts task
end
desc 'done TASK', 'delete a task'
def done(task_index)
`sed -i '#{task_index}d' #{File.basename(@file)}`
end
end
Dolittle.start(ARGV)
# frozen_string_literal: true
source "https://rubygems.org"
# gem "rails"
gem 'thor'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment