todo-cli 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require "todo"
4
+ require "rainbow"
5
+
6
+ cmd = ARGV[0]
7
+ arg = ARGV[1]
8
+
9
+ app = Todo.new cmd, arg
10
+ app.start
@@ -0,0 +1,40 @@
1
+ class Todo
2
+ def initialize (cmd, arg)
3
+ @cmd = cmd
4
+ @arg = arg
5
+ end
6
+
7
+ def start
8
+ case @cmd
9
+ when nil, "help", "h", "?"
10
+ help
11
+ when "status", "show", "s"
12
+ show
13
+ when "delete", "del", "d"
14
+ delete
15
+ when "add", "a", "+"
16
+ error(:task) if @arg.nil?
17
+ add(@arg)
18
+ when "remove", "rm", "r", "-"
19
+ error(:task) if @arg.nil?
20
+ remove(@arg)
21
+ when "check", "c"
22
+ error(:task) if @arg.nil?
23
+ check(@arg)
24
+ when "uncheck", "uc"
25
+ error(:task) if @arg.nil?
26
+ uncheck(@arg)
27
+ else
28
+ error(:cmd)
29
+ end
30
+ end
31
+
32
+ require "todo/help"
33
+ require "todo/error"
34
+ require "todo/show"
35
+ require "todo/delete"
36
+ require "todo/add"
37
+ require "todo/remove"
38
+ require "todo/check"
39
+ require "todo/uncheck"
40
+ end
@@ -0,0 +1,15 @@
1
+ def add (task)
2
+ if File.exist?("TODO")
3
+ content = File.read("TODO")
4
+
5
+ if content[task]
6
+ error(:alreadythere)
7
+ end
8
+ end
9
+
10
+ File.open("TODO", "a") do |file|
11
+ file.puts(task)
12
+ end
13
+
14
+ puts " "+Rainbow("Added").green.bright()+" => "+Rainbow(task).blue.bright()
15
+ end
@@ -0,0 +1,27 @@
1
+ def check (task)
2
+ content = File.read("TODO")
3
+
4
+ if task["..."]
5
+ pattern = task.chomp("...")
6
+ if content =~ /\##{pattern}(.*)\n/
7
+ error(:alreadydone)
8
+ elsif content =~ /#{pattern}(.*)\n/
9
+ content.gsub!(/#{pattern}(.*)\n/, "##{pattern}#{$1}\n")
10
+ else
11
+ error(:notfound)
12
+ end
13
+ output = pattern + $1
14
+ else
15
+ if content =~ /\##{task}\n/
16
+ error(:alreadydone)
17
+ elsif content =~ /#{task}\n/
18
+ content.sub!("#{task}\n", "##{task}\n")
19
+ else
20
+ error(:notfound)
21
+ end
22
+ output = task
23
+ end
24
+
25
+ File.write("TODO", content)
26
+ puts " "+Rainbow("Checked").green.bright()+" => "+Rainbow(output).blue.bright()
27
+ end
@@ -0,0 +1,8 @@
1
+ def delete
2
+ if File.exist?("TODO")
3
+ File.delete("TODO")
4
+ puts " "+Rainbow("Deleted TODO list").green.bright()
5
+ else
6
+ error(:nofile)
7
+ end
8
+ end
@@ -0,0 +1,21 @@
1
+ def error (type)
2
+ case type
3
+ when :cmd
4
+ output = "Invalid command"
5
+ when :task
6
+ output = "You need to specify a task"
7
+ when :nofile
8
+ output = "There is no TODO file in this directory"
9
+ when :notfound
10
+ output = "The given task is not in your TODO list"
11
+ when :alreadythere
12
+ output = "The given task is already in your TODO list"
13
+ when :alreadydone
14
+ output = "The given task is already checked"
15
+ when :notchecked
16
+ output = "The given task is not checked"
17
+ end
18
+
19
+ puts " "+Rainbow(output).red.bright()
20
+ exit
21
+ end
@@ -0,0 +1,12 @@
1
+ def help
2
+ puts "\n"
3
+ puts " $ todo #{Rainbow('[command]').blue.bright} #{Rainbow('[task]').green.bright}\n\n"
4
+ puts " #{Rainbow('show').blue.bright} => Shows the TODO list"
5
+ puts " #{Rainbow('delete').blue.bright} => Deletes the TODO list"
6
+ puts " #{Rainbow('add').blue.bright} #{Rainbow('[task]').green.bright} => Adds a task (creates file if not available)"
7
+ puts " #{Rainbow('rm').blue.bright} #{Rainbow('[task]').green.bright} => Removes a task (removes file when last task)"
8
+ puts " #{Rainbow('check').blue.bright} #{Rainbow('[task]').green.bright} => Markes a task as done"
9
+ puts " #{Rainbow('uncheck').blue.bright} #{Rainbow('[task]').green.bright} => Unmarks a task when already marked\n\n"
10
+ puts " Pro tip: You can match the task #{Rainbow('\'Do something\'').blue.bright} with #{Rainbow('\'Do...\'').blue.bright}"
11
+ puts "\n"
12
+ end
@@ -0,0 +1,27 @@
1
+ def remove (task)
2
+ content = File.read("TODO")
3
+
4
+ if task["..."]
5
+ pattern = task.chomp("...")
6
+ if content =~ /\##{pattern}(.*)\n/
7
+ content.gsub!(/\##{pattern}(.*)\n/, "")
8
+ elsif content =~ /#{pattern}(.*)\n/
9
+ content.gsub!(/#{pattern}(.*)\n/, "")
10
+ else
11
+ error(:notfound)
12
+ end
13
+ output = pattern + $1
14
+ else
15
+ if content =~ /\##{task}\n/
16
+ content.sub!("\##{task}\n", "")
17
+ elsif content =~ /#{task}\n/
18
+ content.sub!("#{task}\n", "")
19
+ else
20
+ error(:notfound)
21
+ end
22
+ output = task
23
+ end
24
+ File.write("TODO", content)
25
+ puts " "+Rainbow("Removed").green.bright()+" => "+Rainbow(output).blue.bright()
26
+ File.delete("TODO") if content == ""
27
+ end
@@ -0,0 +1,19 @@
1
+ #encoding:utf-8
2
+
3
+ def show
4
+ error(:nofile) unless File.exist?("TODO")
5
+
6
+ puts Rainbow("\n Your TODO list:").blue.bright()+" (#{Dir.pwd}/TODO)\n\n"
7
+
8
+ File.read("TODO").each_line do |line|
9
+ if line[0,1] == "#"
10
+ line.sub!("#", "")
11
+ line.sub!("\n", "")
12
+ puts " » "+ Rainbow(line +" ✔").green.bright
13
+ else
14
+ puts " » "+ line
15
+ end
16
+ end
17
+
18
+ puts "\n"
19
+ end
@@ -0,0 +1,27 @@
1
+ def uncheck (task)
2
+ content = File.read("TODO")
3
+
4
+ if task["..."]
5
+ pattern = task.chomp("...")
6
+ if content =~ /\##{pattern}(.*)\n/
7
+ content.gsub!(/##{pattern}(.*)\n/, "#{pattern}#{$1}\n")
8
+ elsif content =~ /#{pattern}(.*)\n/
9
+ error(:notchecked)
10
+ else
11
+ error(:notfound)
12
+ end
13
+ output = pattern + $1
14
+ else
15
+ if content =~ /\##{task}\n/
16
+ content.sub!("##{task}\n", "#{task}\n")
17
+ elsif content =~ /#{task}\n/
18
+ error(:notchecked)
19
+ else
20
+ error(:notfound)
21
+ end
22
+ output = task
23
+ end
24
+
25
+ File.write("TODO", content)
26
+ puts " "+Rainbow("Unchecked").green.bright()+" => "+Rainbow(output).blue.bright()
27
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: todo-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tobiasz Walczak
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-03-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rainbow
16
+ requirement: &13592740 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *13592740
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &13589780 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *13589780
36
+ description:
37
+ email:
38
+ - tobiaszwalczak@gmail.com
39
+ executables:
40
+ - todo
41
+ extensions: []
42
+ extra_rdoc_files: []
43
+ files:
44
+ - lib/todo.rb
45
+ - lib/todo/add.rb
46
+ - lib/todo/delete.rb
47
+ - lib/todo/help.rb
48
+ - lib/todo/error.rb
49
+ - lib/todo/show.rb
50
+ - lib/todo/uncheck.rb
51
+ - lib/todo/remove.rb
52
+ - lib/todo/check.rb
53
+ - bin/todo
54
+ homepage: https://github.com/tobiaszwalczak/Todo-CLI/
55
+ licenses:
56
+ - MIT
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 1.8.11
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: A little command line todo app.
79
+ test_files: []
80
+ has_rdoc: