Created
March 16, 2017 16:59
-
-
Save aziflaj/d4f82aaf05e8293c08ae79f9b30af35b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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