hypertodo 1.0.0 → 1.0.1
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.
- checksums.yaml +4 -4
- data/bin/hypertodo +5 -0
- data/lib/hypertodo.rb +0 -3
- data/lib/hypertodo/command.rb +71 -65
- data/lib/hypertodo/command/options.rb +88 -75
- data/lib/hypertodo/version.rb +1 -1
- metadata +3 -4
- data/bin/console +0 -13
- data/bin/setup +0 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7943f78b505274eb89f357b34380b166e4f6b2a0
|
|
4
|
+
data.tar.gz: 01b1213c8b66b36394310437899fb44e023fa52b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5c6b8b11a87cb0cfbe19f02c83122e218fd13f395701e39fe4a1634121ed34bcc486053c98ec030bb25ed902caafa2542b81360932a62c8d3ac45cde327d1a2d
|
|
7
|
+
data.tar.gz: 4a16a50810440e70164e0c01931beba2325ce5e833961f426f0fbad283411f02bafd85ffd16faf67105e2239afaef91486554f81942f050697fbf915c99e0725
|
data/bin/hypertodo
ADDED
data/lib/hypertodo.rb
CHANGED
data/lib/hypertodo/command.rb
CHANGED
|
@@ -1,86 +1,92 @@
|
|
|
1
1
|
# coding: utf-8
|
|
2
|
-
class Command
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
new(argv).execute
|
|
6
|
-
end
|
|
3
|
+
module Hypertodo
|
|
7
4
|
|
|
8
|
-
|
|
9
|
-
@argv = argv
|
|
10
|
-
end
|
|
5
|
+
class Command
|
|
11
6
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
DB.prepare
|
|
17
|
-
|
|
18
|
-
tasks = case sub_command:
|
|
19
|
-
when 'create'
|
|
20
|
-
create_task(options[:name], options[:content])
|
|
21
|
-
when 'delete'
|
|
22
|
-
delete_task(options[:id])
|
|
23
|
-
when 'update'
|
|
24
|
-
update_task(options.delete(:id), options)
|
|
25
|
-
when 'list'
|
|
26
|
-
find_tasks(options[:status])
|
|
27
|
-
end
|
|
28
|
-
display_tasks tasks
|
|
29
|
-
|
|
30
|
-
rescue => e
|
|
31
|
-
abort "Error: #{e.message}"
|
|
32
|
-
end
|
|
7
|
+
def self.run(argv)
|
|
8
|
+
new(argv).execute
|
|
9
|
+
end
|
|
33
10
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
11
|
+
def initialize(argv)
|
|
12
|
+
@argv = argv
|
|
13
|
+
end
|
|
37
14
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
15
|
+
def execute
|
|
16
|
+
options = Options.parse!(@argv)
|
|
17
|
+
sub_command = options.delete(:command)
|
|
18
|
+
|
|
19
|
+
DB.prepare
|
|
20
|
+
|
|
21
|
+
tasks = case sub_command
|
|
22
|
+
when 'create'
|
|
23
|
+
create_task(options[:name], options[:content])
|
|
24
|
+
when 'delete'
|
|
25
|
+
delete_task(options[:id])
|
|
26
|
+
when 'update'
|
|
27
|
+
update_task(options.delete(:id), options)
|
|
28
|
+
when 'list'
|
|
29
|
+
find_tasks(options[:status])
|
|
30
|
+
end
|
|
31
|
+
display_tasks tasks
|
|
32
|
+
|
|
33
|
+
rescue => e
|
|
34
|
+
abort "Error: #{e.message}"
|
|
35
|
+
end
|
|
42
36
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
37
|
+
def create_task(name, content)
|
|
38
|
+
# タスク作成時のstatusはデフォルト値が使われNOT_YETとなる
|
|
39
|
+
Task.create!(name: name, content: content).reload
|
|
46
40
|
end
|
|
47
41
|
|
|
48
|
-
|
|
49
|
-
|
|
42
|
+
def delete_task(id)
|
|
43
|
+
task = Task.find(id)
|
|
44
|
+
task.destroy
|
|
45
|
+
end
|
|
50
46
|
|
|
51
|
-
|
|
52
|
-
|
|
47
|
+
def update_task(id, attributes)
|
|
48
|
+
if status_name = attributes[:status]
|
|
49
|
+
attributes[:status] = Task::STATUS.fetch(status_name.upcase)
|
|
50
|
+
end
|
|
53
51
|
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
task = Task.find(id)
|
|
53
|
+
task.update_attributes! attributes
|
|
56
54
|
|
|
57
|
-
|
|
58
|
-
status = Task::STATUS.fetch(status_name.upcase)
|
|
59
|
-
all_tasks.status_is(status)
|
|
60
|
-
else
|
|
61
|
-
all_tasks
|
|
55
|
+
task.reload
|
|
62
56
|
end
|
|
63
|
-
end
|
|
64
57
|
|
|
65
|
-
|
|
58
|
+
def find_tasks(status_name)
|
|
59
|
+
all_tasks = Task.order('created_at DESC')
|
|
60
|
+
|
|
61
|
+
if status_name
|
|
62
|
+
status = Task::STATUS.fetch(status_name.upcase)
|
|
63
|
+
all_tasks.status_is(status)
|
|
64
|
+
else
|
|
65
|
+
all_tasks
|
|
66
|
+
end
|
|
67
|
+
end
|
|
66
68
|
|
|
67
|
-
|
|
68
|
-
header = display_format('ID', 'Name', 'Content', 'Status')
|
|
69
|
+
private
|
|
69
70
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
puts
|
|
71
|
+
def display_tasks(tasks)
|
|
72
|
+
header = display_format('ID', 'Name', 'Content', 'Status')
|
|
73
|
+
|
|
74
|
+
puts header
|
|
75
|
+
puts '-' * header.size
|
|
76
|
+
Array(tasks).each do |task|
|
|
77
|
+
puts display_format(task.id, task.name, task.content, task.status_name)
|
|
78
|
+
end
|
|
74
79
|
end
|
|
75
|
-
end
|
|
76
80
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
81
|
+
def display_format(id, name, content, status)
|
|
82
|
+
name_length = 20 - full_width_count(name)
|
|
83
|
+
content_length = 38 - full_width_count(content)
|
|
84
|
+
[id.to_s.rjust(4), name.ljust(name_length), content.ljust(content_length), status.ljust(8)].join(' | ')
|
|
85
|
+
end
|
|
82
86
|
|
|
83
|
-
|
|
84
|
-
|
|
87
|
+
def full_width_count(string)
|
|
88
|
+
string.each_char.select{ |char| !(/[ -~。-゚]/.match(char)) }.count
|
|
89
|
+
end
|
|
85
90
|
end
|
|
91
|
+
|
|
86
92
|
end
|
|
@@ -1,100 +1,113 @@
|
|
|
1
1
|
# coding: utf-8
|
|
2
2
|
|
|
3
3
|
require 'optparse'
|
|
4
|
-
module Options
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
options = {}
|
|
5
|
+
module Hypertodo
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
command_parser = create_command_parser
|
|
7
|
+
class Command
|
|
11
8
|
|
|
12
|
-
|
|
13
|
-
sub_command_parsers[options[:command]].parse! argv
|
|
9
|
+
module Options
|
|
14
10
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
options[:id] = Integer(argv.first)
|
|
18
|
-
end
|
|
19
|
-
rescue OptionParser::MissingArgument, OptionParser::InvalidOption, ArgumentError => e
|
|
20
|
-
abort e.message
|
|
21
|
-
end
|
|
22
|
-
command_parser.order!(argv)
|
|
23
|
-
|
|
24
|
-
options[:command] = argv.shift
|
|
11
|
+
def self.parse!(argv)
|
|
12
|
+
options = {}
|
|
25
13
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
abort e.message
|
|
29
|
-
end
|
|
30
|
-
end
|
|
14
|
+
sub_command_parsers = create_sub_command_parsers
|
|
15
|
+
command_parser = create_command_parser
|
|
31
16
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
end
|
|
17
|
+
# analysis
|
|
18
|
+
begin
|
|
19
|
+
command_parser.order! argv
|
|
36
20
|
|
|
37
|
-
|
|
38
|
-
opt.banner = 'Usage: create <args>'
|
|
39
|
-
opt.on('-n VAL', '--name=VAL', 'task name') {|v| options[:name] = v }
|
|
40
|
-
opt.on('-c VAL', '--content=VAL', 'task content') {|v| options[:content] = v }
|
|
41
|
-
opt.on_tail('-h', '--help', 'Show this message') {|v| help_sub_command(opt) }
|
|
42
|
-
end
|
|
21
|
+
options[:command] = argv.shift
|
|
43
22
|
|
|
44
|
-
|
|
45
|
-
opt.banner = 'Usage: list <args>'
|
|
46
|
-
opt.on('-s VAL', '--status=VAL', 'list status') {|v| options[:status] = v }
|
|
47
|
-
opt.on_tail('-h', '--help', 'Show this message') {|v| help_sub_command(opt) }
|
|
48
|
-
end
|
|
23
|
+
sub_command_parsers[options[:command]].parse! argv
|
|
49
24
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
25
|
+
if %w(update delete).include?(options[:command])
|
|
26
|
+
raise ArgumentError, "#{options[:command]} id not found." if argv.empty?
|
|
27
|
+
options[:id] = Integer(argv.first)
|
|
28
|
+
end
|
|
29
|
+
rescue OptionParser::MissingArgument, OptionParser::InvalidOption, ArgumentError => e
|
|
30
|
+
abort e.message
|
|
31
|
+
end
|
|
57
32
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
opt.on_tail('-h', '--help', 'Show this message') {|v| help_sub_command(opt) }
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
sub_command_parsers
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
def self.help_sub_command(parser)
|
|
67
|
-
puts parser.help
|
|
68
|
-
exit
|
|
69
|
-
end
|
|
33
|
+
options
|
|
34
|
+
end
|
|
70
35
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
36
|
+
def self.create_sub_command_parsers(options)
|
|
37
|
+
sub_command_parsers = Hash.new do |k, v|
|
|
38
|
+
raise ArgumentError, "'#{v}' is not todo sub command."
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
sub_command_parsers['create'] = OptionParser.new do |opt|
|
|
42
|
+
opt.banner = 'Usage: create <args>'
|
|
43
|
+
opt.on('-n VAL', '--name=VAL', 'task name') {|v| options[:name] = v }
|
|
44
|
+
opt.on('-c VAL', '--content=VAL', 'task content') {|v| options[:content] = v }
|
|
45
|
+
opt.on_tail('-h', '--help', 'Show this message') {|v| help_sub_command(opt) }
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
sub_command_parsers['list'] = OptionParser.new do |opt|
|
|
49
|
+
opt.banner = 'Usage: list <args>'
|
|
50
|
+
opt.on('-s VAL', '--status=VAL', 'list status') {|v| options[:status] = v }
|
|
51
|
+
opt.on_tail('-h', '--help', 'Show this message') {|v| help_sub_command(opt) }
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
sub_command_parsers['update'] = OptionParser.new do |opt|
|
|
55
|
+
opt.banner = 'Usage: update id <args>'
|
|
56
|
+
opt.on('-n VAL', '--name=VAL', 'update name') {|v| options[:name] = v }
|
|
57
|
+
opt.on('-c VAL', '--content=VAL' 'update content') {|v| options[:content] = v }
|
|
58
|
+
opt.on('-s VAL', '--status=VAL', 'update status') {|v| options[:status] = v }
|
|
59
|
+
opt.on_tail('-h', '--help', 'Shoe this message') {|v| help_sub_command(opt) }
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
sub_command_parsers['delete'] = OptionParser.new do |opt|
|
|
63
|
+
opt.banner = 'Usage: delete id'
|
|
64
|
+
opt.on_tail('-h', '--help', 'Show this message') {|v| help_sub_command(opt) }
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
sub_command_parsers
|
|
84
68
|
end
|
|
85
69
|
|
|
86
|
-
|
|
87
|
-
puts
|
|
70
|
+
def self.help_sub_command(parser)
|
|
71
|
+
puts parser.help
|
|
88
72
|
exit
|
|
89
73
|
end
|
|
90
74
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
75
|
+
def self.create_command_parser
|
|
76
|
+
OptionParser.new do |opt|
|
|
77
|
+
sub_command_help = [
|
|
78
|
+
{name: 'create -n name -c content', summary: 'Create Todo Task'},
|
|
79
|
+
{name: 'update id -n name -c content -s status', summary: 'Update Todo Task'},
|
|
80
|
+
{name: 'list -s status', summary: 'List Todo Tasks'},
|
|
81
|
+
{name: 'delete id', summary: 'Delete Todo Task'}
|
|
82
|
+
]
|
|
83
|
+
opt.banner = "Usage: #{opt.program_name} [-h|--help][-v|--version] <command> [<args>]"
|
|
84
|
+
opt.separator ''
|
|
85
|
+
opt.separator "#{opt.program_name} Available Commands:"
|
|
86
|
+
sub_command_help.each do |command|
|
|
87
|
+
opt.separator [opt.summary_indent, command[:name].ljust(40), command[:summary]].join(' ')
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
opt.on_head('-h', '--help', 'Show this message') do |v|
|
|
91
|
+
puts opt.help
|
|
92
|
+
exit
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
opt.on_head('-v', '--version', 'Show program version') do |v|
|
|
96
|
+
opt.version = Todo::VERSION
|
|
97
|
+
puts opt.ver
|
|
98
|
+
exit
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def self.help_sub_command(parser)
|
|
104
|
+
puts parse.help
|
|
94
105
|
exit
|
|
95
106
|
end
|
|
107
|
+
|
|
108
|
+
private_class_method :create_sub_command_parsers, :create_command_parser, :help_sub_command
|
|
96
109
|
end
|
|
110
|
+
|
|
97
111
|
end
|
|
98
112
|
|
|
99
|
-
private_class_method :create_sub_command_parsers, :create_command_parser, :help_sub_command
|
|
100
113
|
end
|
data/lib/hypertodo/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: hypertodo
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- chansuke
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-11-
|
|
11
|
+
date: 2015-11-18 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activerecord
|
|
@@ -109,8 +109,7 @@ files:
|
|
|
109
109
|
- LICENSE.txt
|
|
110
110
|
- README.md
|
|
111
111
|
- Rakefile
|
|
112
|
-
- bin/
|
|
113
|
-
- bin/setup
|
|
112
|
+
- bin/hypertodo
|
|
114
113
|
- exe/hypertodo
|
|
115
114
|
- hypertodo.gemspec
|
|
116
115
|
- lib/hypertodo.rb
|
data/bin/console
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
|
|
3
|
-
require "bundler/setup"
|
|
4
|
-
require "hypertodo"
|
|
5
|
-
|
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
-
|
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
-
require "pry"
|
|
11
|
-
Pry.start
|
|
12
|
-
|
|
13
|
-
Todo::Command.run(ARGV)
|