tdoo 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/tdoo +54 -33
- data/lib/tdoo.rb +2 -1
- data/lib/tdoo/format/pretty.rb +42 -0
- data/lib/tdoo/version.rb +1 -1
- metadata +21 -14
- data/README.rdoc +0 -1
- data/tdoo.rdoc +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04db06e81be29428459a1aa908d21a4783b77f65
|
4
|
+
data.tar.gz: a34ac90f6f22a9df5c745caf62a700f2d91be4dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 340abbfc995671672af1350ad246e0d9af0bc2d8f19983eb079600b6a9826192440593803560e11a3f1e58da3ff75229c5511ac31c8d19a05c438e1b58843a6b
|
7
|
+
data.tar.gz: 3feb257ed75227c0c014f0f3033127aef259124af28774d88b6b88afeb36b546f8ffda0caa249f5dc52c708869cf516fc9e67501f8321129f65964cc0a90ab2e
|
data/bin/tdoo
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'gli'
|
3
|
-
require '
|
3
|
+
require 'tdoo'
|
4
4
|
|
5
5
|
include GLI::App
|
6
|
+
|
6
7
|
program_desc 'A mini todo command-line application'
|
7
8
|
|
9
|
+
version Tdoo::VERSION
|
10
|
+
|
8
11
|
desc 'Path to the todo file'
|
9
12
|
default_value '~/.tdoo.txt'
|
10
13
|
arg_name 'todo_file'
|
@@ -12,8 +15,8 @@ flag [:f,:filename]
|
|
12
15
|
|
13
16
|
desc 'Create a new task in the task list'
|
14
17
|
long_desc "
|
15
|
-
A task has a name and
|
16
|
-
|
18
|
+
A task has a name and belongs to a project that you need to specify.
|
19
|
+
e.g. tdoo new -p today \"Happy coding!\"
|
17
20
|
"
|
18
21
|
arg_name 'task'
|
19
22
|
command [:new, :n] do |c|
|
@@ -21,9 +24,6 @@ command [:new, :n] do |c|
|
|
21
24
|
c.arg_name 'project'
|
22
25
|
c.flag [:p, :project]
|
23
26
|
|
24
|
-
c.desc 'put the new task first in the task list'
|
25
|
-
c.switch :f
|
26
|
-
|
27
27
|
c.action do |global_options,options,task_names|
|
28
28
|
data = File.expand_path(global_options[:filename])
|
29
29
|
unless File.exist?(data)
|
@@ -31,8 +31,9 @@ command [:new, :n] do |c|
|
|
31
31
|
File.new(data, 'w+')
|
32
32
|
end
|
33
33
|
|
34
|
+
formatter = Tdoo::Format::Pretty.new
|
34
35
|
File.open(data, 'a+') do |todo_file|
|
35
|
-
raise "You must specify the project's name that new tasks belong to" if options[:p].nil?
|
36
|
+
raise "You must specify the project's name that new tasks belong to... 'tdoo new -h' for help!" if options[:p].nil?
|
36
37
|
|
37
38
|
if task_names.empty?
|
38
39
|
puts "Reading new tasks from stdin..."
|
@@ -49,80 +50,100 @@ command [:new, :n] do |c|
|
|
49
50
|
task_names.each_with_index do |task, index|
|
50
51
|
t = Time.now.strftime("%Y-%m-%d %H:%M:%S")
|
51
52
|
todo_file.puts [project, index+tasks, task, t].join(',')
|
52
|
-
|
53
|
+
formatter.format_todo(project, index+tasks, task, t)
|
53
54
|
end
|
55
|
+
|
56
|
+
formatter.after
|
54
57
|
end
|
55
58
|
end
|
56
59
|
end
|
57
60
|
|
58
61
|
desc 'List all tasks'
|
62
|
+
long_desc "
|
63
|
+
By default, the format of the output is pretty. A task has two status, todo and done, that will be
|
64
|
+
different colors. Red is for todo tasks and green is for done tasks instead.
|
65
|
+
e.g. tdoo list -p today
|
66
|
+
"
|
59
67
|
command [:list, :ls] do |c|
|
60
|
-
c.desc 'Format of the output (pretty for TTY, csv otherwise)'
|
61
|
-
c.arg_name 'csv|pretty'
|
62
|
-
c.flag :format
|
63
68
|
|
64
69
|
c.desc 'List all tasks belong to a certain project'
|
65
70
|
c.arg_name 'project'
|
66
71
|
c.flag [:p, :project]
|
67
72
|
|
68
73
|
c.action do |global_options,options,args|
|
69
|
-
if options[:format].nil?
|
70
|
-
options[:format] = STDOUT.tty? ? 'pretty' : 'csv'
|
71
|
-
end
|
72
74
|
|
75
|
+
formatter = Tdoo::Format::Pretty.new
|
76
|
+
project_flag = options[:p].nil? ? false : true
|
73
77
|
data = File.read(File.expand_path(global_options[:filename]))
|
74
|
-
|
75
|
-
|
76
|
-
|
78
|
+
data.each_line do |line|
|
79
|
+
field = line.chomp.split(',')
|
80
|
+
project = field[0]
|
81
|
+
completed = field.count
|
82
|
+
if project_flag
|
83
|
+
if (completed == 4) && (project == options[:p])
|
84
|
+
formatter.format_todo(field[0], field[1], field[2], field[3])
|
85
|
+
elsif project == options[:p]
|
86
|
+
formatter.format_done(field[0], field[1], field[2], field[3], field[4])
|
87
|
+
end
|
88
|
+
else
|
77
89
|
if completed == 4
|
78
|
-
|
90
|
+
formatter.format_todo(field[0], field[1], field[2], field[3])
|
79
91
|
else
|
80
|
-
|
81
|
-
end
|
82
|
-
end
|
83
|
-
else
|
84
|
-
data.each_line do |line|
|
85
|
-
project = line.chomp.split(',')[0]
|
86
|
-
completed = line.chomp.split(',').count
|
87
|
-
if project == options[:p]
|
88
|
-
if completed == 4
|
89
|
-
puts line.color(:red)
|
90
|
-
else
|
91
|
-
puts line.color(:green)
|
92
|
-
end
|
92
|
+
formatter.format_done(field[0], field[1], field[2], field[3], field[4])
|
93
93
|
end
|
94
94
|
end
|
95
95
|
end
|
96
|
+
|
97
|
+
formatter.after
|
96
98
|
end
|
97
99
|
end
|
98
100
|
|
99
101
|
desc 'Complete a task'
|
100
102
|
arg_name 'task_number'
|
103
|
+
long_desc "
|
104
|
+
Done tasks will be added the completed time after the end of task.
|
105
|
+
However, done tasks will be deleted permanently if you turn the delete switch on.
|
106
|
+
e.g. tdoo done -d -p today 0
|
107
|
+
"
|
101
108
|
command [:done, :d] do |c|
|
102
109
|
c.desc 'specify the project\'s name that done tasks belong to'
|
103
110
|
c.arg_name 'project'
|
104
111
|
c.flag [:p, :project]
|
105
112
|
|
113
|
+
c.desc 'delete the done tasks'
|
114
|
+
c.switch [:d, :delete]
|
115
|
+
|
106
116
|
c.action do |global_options,options,task_number|
|
107
117
|
old_file = File.expand_path(global_options[:filename])
|
108
118
|
new_file = old_file + '.new'
|
119
|
+
delete_switch = options[:d] ? true : false
|
109
120
|
|
121
|
+
formatter = Tdoo::Format::Pretty.new
|
110
122
|
File.open(old_file, 'r') do |todo_file|
|
111
|
-
raise "You must specify the project's name that done tasks belong to" if options[:p].nil?
|
123
|
+
raise "You must specify the project's name that done tasks belong to...'tdoo done -h' for help!" if options[:p].nil?
|
124
|
+
raise "you must point the done task number out...'tdoo done -h' for help!" if task_number.empty?
|
112
125
|
|
126
|
+
# Open a new file and write into tasks which meet some conditions.
|
127
|
+
# A done task can be split up into 5 pieces.
|
113
128
|
File.open(new_file, 'w+') do |new_todo_file|
|
114
129
|
todo_file.readlines.each do |line|
|
115
130
|
field = line.chomp.split(',')
|
116
131
|
project, number = field[0], field[1]
|
117
132
|
if (project == options[:p]) && (field[1] == task_number.first) && (field.count == 4)
|
118
133
|
t = Time.now.strftime("%Y-%m-%d %H:%M:%S")
|
119
|
-
new_todo_file.puts("#{line.chomp}"+",#{t}")
|
134
|
+
new_todo_file.puts("#{line.chomp}"+",#{t}") unless delete_switch
|
135
|
+
formatter.format_done(field[0], field[1], field[2], field[3], t)
|
136
|
+
elsif (project == options[:p]) && (field[1] == task_number.first) && (field.count == 5)
|
137
|
+
new_todo_file.puts(line) unless delete_switch
|
138
|
+
formatter.format_done(field[0], field[1], field[2], field[3], field[4])
|
120
139
|
else
|
121
140
|
new_todo_file.puts(line)
|
122
141
|
end
|
123
142
|
end
|
124
143
|
end
|
125
144
|
end
|
145
|
+
|
146
|
+
formatter.after
|
126
147
|
`rm #{old_file} && mv #{new_file} #{old_file}`
|
127
148
|
end
|
128
149
|
end
|
data/lib/tdoo.rb
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
require 'tdoo/version.rb'
|
1
|
+
require 'tdoo/version.rb'
|
2
|
+
require 'tdoo/format/pretty'
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'terminal-table'
|
2
|
+
require 'rainbow'
|
3
|
+
require 'time'
|
4
|
+
|
5
|
+
module Tdoo
|
6
|
+
module Format
|
7
|
+
class Pretty
|
8
|
+
def initialize
|
9
|
+
@table = Terminal::Table.new headings: %w(project id name created completed)
|
10
|
+
end
|
11
|
+
|
12
|
+
def format_todo(project, index, task, created)
|
13
|
+
row = []
|
14
|
+
row << project.color(:blue)
|
15
|
+
row << index
|
16
|
+
row << task.color(:red)
|
17
|
+
row << as_date(created).color(:red)
|
18
|
+
row << ''
|
19
|
+
@table << row
|
20
|
+
end
|
21
|
+
|
22
|
+
def format_done(project, index, task, created, completed)
|
23
|
+
row = []
|
24
|
+
row << project.color(:blue)
|
25
|
+
row << index
|
26
|
+
row << task.color(:green)
|
27
|
+
row << as_date(created).color(:green)
|
28
|
+
row << as_date(completed).color(:green)
|
29
|
+
@table << row
|
30
|
+
end
|
31
|
+
|
32
|
+
def after
|
33
|
+
puts @table.to_s
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
def as_date(string)
|
38
|
+
Time.parse(string).strftime("%Y-%m-%d %H:%M:%S")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/tdoo/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tdoo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- v4lour
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -80,30 +80,37 @@ dependencies:
|
|
80
80
|
- - '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
-
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: terminal-table
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: You can create, list and check tasks via this simple gem.
|
84
98
|
email: v4lour@gmail.com
|
85
99
|
executables:
|
86
100
|
- tdoo
|
87
101
|
extensions: []
|
88
|
-
extra_rdoc_files:
|
89
|
-
- README.rdoc
|
90
|
-
- tdoo.rdoc
|
102
|
+
extra_rdoc_files: []
|
91
103
|
files:
|
92
104
|
- bin/tdoo
|
93
105
|
- lib/tdoo/version.rb
|
106
|
+
- lib/tdoo/format/pretty.rb
|
94
107
|
- lib/tdoo.rb
|
95
|
-
|
96
|
-
- tdoo.rdoc
|
97
|
-
homepage: http://schil.me/
|
108
|
+
homepage: https://github.com/v4lour/tdoo.git
|
98
109
|
licenses:
|
99
110
|
- MIT
|
100
111
|
metadata: {}
|
101
112
|
post_install_message:
|
102
|
-
rdoc_options:
|
103
|
-
- --title
|
104
|
-
- tdoo
|
105
|
-
- --main
|
106
|
-
- README.rdoc
|
113
|
+
rdoc_options: []
|
107
114
|
require_paths:
|
108
115
|
- lib
|
109
116
|
- lib
|
data/README.rdoc
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
A mini todo command-line app
|