tdoo 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5c4ea10f20869c412048938a3237066857457729
4
+ data.tar.gz: 10b23ca1aaab053ab1f98a4ba147d74f8edc5348
5
+ SHA512:
6
+ metadata.gz: c2660439f97a7e8405c8fa1c45677f510ce162a1df0fe2648b68ec81d5871065a8ed7983947182edf42090decb93e05b0cc6e061c5c8d9ee224c68df2eae1037
7
+ data.tar.gz: ed9623b62a829cce62b68392eb2dfc368f1495f7435ca467ac1aea17125c0cc29916f6e61da218b5deeb07b3fe8d014516ae70a07a41b4605211b880f282b088
data/README.rdoc ADDED
@@ -0,0 +1 @@
1
+ A mini todo command-line app
data/bin/tdoo ADDED
@@ -0,0 +1,141 @@
1
+ #!/usr/bin/env ruby
2
+ require 'gli'
3
+ require 'rainbow'
4
+
5
+ include GLI::App
6
+ program_desc 'A mini todo command-line application'
7
+
8
+ desc 'Path to the todo file'
9
+ default_value '~/.tdoo.txt'
10
+ arg_name 'todo_file'
11
+ flag [:f,:filename]
12
+
13
+ desc 'Create a new task in the task list'
14
+ long_desc "
15
+ A task has a name and a priority. By default, new tasks has the lowest
16
+ priority, though this can be overridden
17
+ "
18
+ arg_name 'task'
19
+ command [:new, :n] do |c|
20
+ c.desc 'specify the project'
21
+ c.arg_name 'project'
22
+ c.flag [:p, :project]
23
+
24
+ c.desc 'put the new task first in the task list'
25
+ c.switch :f
26
+
27
+ c.action do |global_options,options,task_names|
28
+ data = File.expand_path(global_options[:filename])
29
+ unless File.exist?(data)
30
+ puts "Creating #{data}"
31
+ File.new(data, 'w+')
32
+ end
33
+
34
+ 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
+
37
+ if task_names.empty?
38
+ puts "Reading new tasks from stdin..."
39
+ task_names = STDIN.readlines.map { |a| a.chomp }
40
+ end
41
+
42
+ project = options[:p]
43
+
44
+ tasks = 0
45
+ todo_file.each_line do |line|
46
+ tasks += 1 if line.chomp.split(',')[0] == project
47
+ end
48
+
49
+ task_names.each_with_index do |task, index|
50
+ t = Time.now.strftime("%Y-%m-%d %H:%M:%S")
51
+ todo_file.puts [project, index+tasks, task, t].join(',')
52
+ puts [project, index+tasks, task, ].join(',')
53
+ end
54
+ end
55
+ end
56
+ end
57
+
58
+ desc 'List all tasks'
59
+ 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
+
64
+ c.desc 'List all tasks belong to a certain project'
65
+ c.arg_name 'project'
66
+ c.flag [:p, :project]
67
+
68
+ c.action do |global_options,options,args|
69
+ if options[:format].nil?
70
+ options[:format] = STDOUT.tty? ? 'pretty' : 'csv'
71
+ end
72
+
73
+ data = File.read(File.expand_path(global_options[:filename]))
74
+ if options[:p].nil?
75
+ data.each_line do |line|
76
+ completed = line.chomp.split(',').count
77
+ if completed == 4
78
+ puts line.color(:red)
79
+ else
80
+ puts line.color(:green)
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
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
98
+
99
+ desc 'Complete a task'
100
+ arg_name 'task_number'
101
+ command [:done, :d] do |c|
102
+ c.desc 'specify the project\'s name that done tasks belong to'
103
+ c.arg_name 'project'
104
+ c.flag [:p, :project]
105
+
106
+ c.action do |global_options,options,task_number|
107
+ old_file = File.expand_path(global_options[:filename])
108
+ new_file = old_file + '.new'
109
+
110
+ 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?
112
+
113
+ File.open(new_file, 'w+') do |new_todo_file|
114
+ todo_file.readlines.each do |line|
115
+ field = line.chomp.split(',')
116
+ project, number = field[0], field[1]
117
+ if (project == options[:p]) && (field[1] == task_number.first) && (field.count == 4)
118
+ t = Time.now.strftime("%Y-%m-%d %H:%M:%S")
119
+ new_todo_file.puts("#{line.chomp}"+",#{t}")
120
+ else
121
+ new_todo_file.puts(line)
122
+ end
123
+ end
124
+ end
125
+ end
126
+ `rm #{old_file} && mv #{new_file} #{old_file}`
127
+ end
128
+ end
129
+
130
+ pre do |global,command,options,args|
131
+ true
132
+ end
133
+
134
+ post do |global,command,options,args|
135
+ end
136
+
137
+ on_error do |exception|
138
+ true
139
+ end
140
+
141
+ exit run(ARGV)
@@ -0,0 +1,3 @@
1
+ module Tdoo
2
+ VERSION = '0.0.2'
3
+ end
data/lib/tdoo.rb ADDED
@@ -0,0 +1 @@
1
+ require 'tdoo/version.rb'
data/tdoo.rdoc ADDED
@@ -0,0 +1,5 @@
1
+ = tdoo
2
+
3
+ Generate this with
4
+ tdoo rdoc
5
+ After you have described your command line interface
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tdoo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - v4lour
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rdoc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: aruba
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: gli
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 2.8.1
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 2.8.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: rainbow
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email: v4lour@gmail.com
85
+ executables:
86
+ - tdoo
87
+ extensions: []
88
+ extra_rdoc_files:
89
+ - README.rdoc
90
+ - tdoo.rdoc
91
+ files:
92
+ - bin/tdoo
93
+ - lib/tdoo/version.rb
94
+ - lib/tdoo.rb
95
+ - README.rdoc
96
+ - tdoo.rdoc
97
+ homepage: http://schil.me/
98
+ licenses:
99
+ - MIT
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options:
103
+ - --title
104
+ - tdoo
105
+ - --main
106
+ - README.rdoc
107
+ require_paths:
108
+ - lib
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.1.11
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: A mini todo command-line application
126
+ test_files: []