milkode 0.6.3 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -4
- data/HISTORY.ja.rdoc +21 -0
- data/HISTORY.rdoc +14 -0
- data/Rakefile +1 -7
- data/VERSION +1 -1
- data/bin/gmilk +1 -1
- data/bin/milk +3 -3
- data/lib/milkode/cdstk/cdstk.rb +68 -23
- data/lib/milkode/cdweb/app.rb +1 -1
- data/lib/milkode/cdweb/lib/database.rb +8 -1
- data/lib/milkode/cdweb/views/layout.haml +1 -1
- data/lib/milkode/cli.rb +249 -0
- data/lib/milkode/grep/cli_grep.rb +2 -2
- data/milkode.gemspec +22 -16
- data/test/milkode_test_work.rb +1 -1
- data/test/test_cdstk.rb +1 -1
- data/test/{test_cli_cdstk.rb → test_cli.rb} +41 -28
- data/test/test_yaml_file_wrapper.rb +6 -4
- metadata +82 -45
- data/Gemfile.lock +0 -18
- data/lib/milkode/cdstk/cli_cdstk.rb +0 -149
- data/lib/milkode/cdstk/cli_cdstksub.rb +0 -184
- data/test/test_bin_exec.rb +0 -28
data/Gemfile.lock
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
GEM
|
2
|
-
remote: http://rubygems.org/
|
3
|
-
specs:
|
4
|
-
git (1.2.5)
|
5
|
-
jeweler (1.5.2)
|
6
|
-
bundler (~> 1.0.0)
|
7
|
-
git (>= 1.2.5)
|
8
|
-
rake
|
9
|
-
rake (0.8.7)
|
10
|
-
rcov (0.9.9)
|
11
|
-
|
12
|
-
PLATFORMS
|
13
|
-
ruby
|
14
|
-
|
15
|
-
DEPENDENCIES
|
16
|
-
bundler (~> 1.0.0)
|
17
|
-
jeweler (~> 1.5.2)
|
18
|
-
rcov
|
@@ -1,149 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
require 'optparse'
|
3
|
-
require 'milkode/cdstk/cli_cdstksub'
|
4
|
-
require 'milkode/cdstk/cdstk'
|
5
|
-
require 'milkode/common/dbdir.rb'
|
6
|
-
require 'milkode/cdweb/cli_cdweb'
|
7
|
-
require 'milkode/grep/cli_grep'
|
8
|
-
include Milkode
|
9
|
-
|
10
|
-
module Milkode
|
11
|
-
class CLI_Cdstk
|
12
|
-
def self.execute(stdout, arguments=[])
|
13
|
-
opt = OptionParser.new <<EOF
|
14
|
-
#{File.basename($0)} COMMAND [ARGS]
|
15
|
-
|
16
|
-
The most commonly used #{File.basename($0)} are:
|
17
|
-
add Add packages.
|
18
|
-
cleanup Cleanup garbage records.
|
19
|
-
dir Disp package dir.
|
20
|
-
dump Dump records.
|
21
|
-
grep Print lines matching a pattern
|
22
|
-
ignore Ignore setting.
|
23
|
-
info Disp information.
|
24
|
-
init Init db.
|
25
|
-
list List packages.
|
26
|
-
mcd Print 'mcd' command.
|
27
|
-
pwd Disp current db.
|
28
|
-
rebuild Rebuild db.
|
29
|
-
remove Remove packages.
|
30
|
-
setdb Set default db.
|
31
|
-
update Update packages.
|
32
|
-
web Run web-app.
|
33
|
-
EOF
|
34
|
-
|
35
|
-
opt.order!(arguments)
|
36
|
-
subcommand = arguments.shift
|
37
|
-
|
38
|
-
case subcommand
|
39
|
-
when 'grep'
|
40
|
-
Milkode::CLI_Grep.execute(stdout, arguments)
|
41
|
-
else
|
42
|
-
subcommand_default(stdout, opt, subcommand, arguments)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
private
|
47
|
-
|
48
|
-
def self.subcommand_default(stdout, opt, subcommand, arguments)
|
49
|
-
subopt = Hash.new
|
50
|
-
suboptions = Hash.new
|
51
|
-
|
52
|
-
subopt['init'], suboptions['init'] = CLI_Cdstksub.setup_init
|
53
|
-
subopt['add'], suboptions['add'] = CLI_Cdstksub.setup_add
|
54
|
-
subopt['update'], suboptions['update'] = CLI_Cdstksub.setup_update
|
55
|
-
subopt['remove'], suboptions['remove'] = CLI_Cdstksub.setup_remove
|
56
|
-
subopt['list'], suboptions['list'] = CLI_Cdstksub.setup_list
|
57
|
-
subopt['pwd'], suboptions['pwd'] = CLI_Cdstksub.setup_pwd
|
58
|
-
subopt['cleanup'], suboptions['cleanup'] = CLI_Cdstksub.setup_cleanup
|
59
|
-
subopt['rebuild'], suboptions['rebuild'] = CLI_Cdstksub.setup_rebuild
|
60
|
-
subopt['dump'] = OptionParser.new("#{File.basename($0)} dump")
|
61
|
-
subopt['web'], suboptions['web'] = CLI_Cdstksub.setup_web
|
62
|
-
subopt['dir'], suboptions['dir'] = CLI_Cdstksub.setup_dir
|
63
|
-
subopt['setdb'], suboptions['setdb'] = CLI_Cdstksub.setup_setdb
|
64
|
-
subopt['mcd'], suboptions['mcd'] = CLI_Cdstksub.setup_mcd
|
65
|
-
subopt['info'], suboptions['info'] = CLI_Cdstksub.setup_info
|
66
|
-
subopt['ignore'], suboptions['ignore'] = CLI_Cdstksub.setup_ignore
|
67
|
-
|
68
|
-
if (subopt[subcommand])
|
69
|
-
subopt[subcommand].parse!(arguments) unless arguments.empty?
|
70
|
-
init_default = suboptions['init'][:init_default]
|
71
|
-
|
72
|
-
db_dir = select_dbdir(subcommand, init_default, arguments)
|
73
|
-
obj = Cdstk.new(stdout, db_dir)
|
74
|
-
|
75
|
-
case subcommand
|
76
|
-
when 'init'
|
77
|
-
if (arguments.size <= 1)
|
78
|
-
FileUtils.mkdir_p db_dir if (init_default || init_specify_dbddir?(arguments))
|
79
|
-
obj.init(suboptions[subcommand])
|
80
|
-
else
|
81
|
-
$stderr.puts "milk init [db_dir] (Cannot specify two 'db_dir')"
|
82
|
-
end
|
83
|
-
when 'update'
|
84
|
-
obj.update(arguments, suboptions[subcommand])
|
85
|
-
when 'add'
|
86
|
-
obj.add(arguments, suboptions[subcommand])
|
87
|
-
when 'remove'
|
88
|
-
obj.remove(arguments, suboptions[subcommand])
|
89
|
-
when 'list'
|
90
|
-
obj.list(arguments, suboptions[subcommand])
|
91
|
-
when 'pwd'
|
92
|
-
obj.pwd(suboptions[subcommand])
|
93
|
-
when 'cleanup'
|
94
|
-
obj.cleanup(suboptions[subcommand])
|
95
|
-
when 'rebuild'
|
96
|
-
obj.rebuild(arguments, suboptions[subcommand])
|
97
|
-
when 'dump'
|
98
|
-
obj.dump
|
99
|
-
when 'web'
|
100
|
-
obj.compatible?
|
101
|
-
Milkode::CLI_Cdweb.execute_with_options(stdout, suboptions[subcommand])
|
102
|
-
when 'dir'
|
103
|
-
obj.dir(arguments, suboptions[subcommand])
|
104
|
-
when 'setdb'
|
105
|
-
obj.setdb(arguments, suboptions[subcommand])
|
106
|
-
when 'mcd'
|
107
|
-
obj.mcd(arguments, suboptions[subcommand])
|
108
|
-
when 'info'
|
109
|
-
obj.info(arguments, suboptions[subcommand])
|
110
|
-
when 'ignore'
|
111
|
-
begin
|
112
|
-
obj.ignore(arguments, suboptions[subcommand])
|
113
|
-
rescue IgnoreError => e
|
114
|
-
stdout.puts e.message
|
115
|
-
end
|
116
|
-
end
|
117
|
-
else
|
118
|
-
if subcommand
|
119
|
-
$stderr.puts "#{File.basename($0)}: '#{subcommand}' is not a #{File.basename($0)} command. See '#{File.basename($0)} --help'"
|
120
|
-
else
|
121
|
-
stdout.puts opt.help
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
def self.select_dbdir(subcommand, init_default, arguments)
|
127
|
-
if (subcommand == 'init')
|
128
|
-
if (init_specify_dbddir?(arguments))
|
129
|
-
arguments[0]
|
130
|
-
elsif (init_default)
|
131
|
-
Dbdir.default_dir
|
132
|
-
else
|
133
|
-
'.'
|
134
|
-
end
|
135
|
-
else
|
136
|
-
if (Dbdir.dbdir?('.') || !Dbdir.dbdir?(Dbdir.default_dir))
|
137
|
-
'.'
|
138
|
-
else
|
139
|
-
Dbdir.default_dir
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
def self.init_specify_dbddir?(arguments)
|
145
|
-
arguments.size == 1
|
146
|
-
end
|
147
|
-
|
148
|
-
end
|
149
|
-
end
|
@@ -1,184 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
require 'optparse'
|
3
|
-
require 'milkode/cdstk/cdstk'
|
4
|
-
require 'milkode/common/dbdir.rb'
|
5
|
-
require 'milkode/cdweb/cli_cdweb'
|
6
|
-
include Milkode
|
7
|
-
|
8
|
-
module Milkode
|
9
|
-
class CLI_Cdstksub
|
10
|
-
def self.setup_init
|
11
|
-
options = {:init_default => false}
|
12
|
-
|
13
|
-
opt = OptionParser.new("#{File.basename($0)} init [db_dir]")
|
14
|
-
opt.on('--default', 'Init default db, ENV[\'MILKODE_DEFAULT_DIR\'] or ~/.milkode.') { options[:init_default] = true }
|
15
|
-
opt.on('-s', '--setdb', 'With setdb.') { options[:setdb] = true }
|
16
|
-
|
17
|
-
return opt, options
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.setup_add
|
21
|
-
bin = File.basename($0)
|
22
|
-
|
23
|
-
options = {:ignore => []}
|
24
|
-
|
25
|
-
opt = OptionParser.new(<<EOF)
|
26
|
-
#{bin} add dir1 [dir2 ...]
|
27
|
-
usage:
|
28
|
-
#{bin} add /path/to/dir1
|
29
|
-
#{bin} add /path/to/dir2 /path/to/dir3
|
30
|
-
#{bin} add /path/is/*
|
31
|
-
#{bin} add /path/to/zipfile.zip
|
32
|
-
#{bin} add /path/to/addon.xpi
|
33
|
-
#{bin} add http://example.com/urlfile.zip
|
34
|
-
|
35
|
-
option:
|
36
|
-
EOF
|
37
|
-
# opt.on('-n NAME', '--name NAME', 'Specify name (default: File.basename(dir))') {|v| options[:name] = v }
|
38
|
-
opt.on('-i PATH', '--ignore PATH', 'Ignore path.') {|v| options[:ignore] << v }
|
39
|
-
opt.on('--no-auto-ignore', 'Disable auto ignore (.gitignore)') { options[:no_auto_ignore] = true }
|
40
|
-
opt.on('-v', '--verbose', 'Be verbose.') { options[:verbose] = true }
|
41
|
-
|
42
|
-
return opt, options
|
43
|
-
end
|
44
|
-
|
45
|
-
def self.setup_update
|
46
|
-
options = {:force => false}
|
47
|
-
|
48
|
-
opt = OptionParser.new("#{File.basename($0)} update [keyword1 keyword2 ...]")
|
49
|
-
opt.on('--all', 'Update all.') { options[:all] = true }
|
50
|
-
opt.on('-v', '--verbose', 'Be verbose.') { options[:verbose] = true }
|
51
|
-
|
52
|
-
return opt, options
|
53
|
-
end
|
54
|
-
|
55
|
-
def self.setup_remove
|
56
|
-
options = {:force => false}
|
57
|
-
|
58
|
-
opt = OptionParser.new("#{File.basename($0)} remove keyword1 [keyword2 ...]")
|
59
|
-
opt.on('--all', 'Update all.') { options[:all] = true }
|
60
|
-
opt.on('-f', '--force', 'Force remove.') { options[:force] = true }
|
61
|
-
opt.on('-v', '--verbose', 'Be verbose.') { options[:verbose] = true }
|
62
|
-
|
63
|
-
return opt, options
|
64
|
-
end
|
65
|
-
|
66
|
-
def self.setup_list
|
67
|
-
options = {:verbose => false}
|
68
|
-
|
69
|
-
opt = OptionParser.new("#{File.basename($0)} list package1 [package2 ...]") # @todo コメント修正
|
70
|
-
opt.on('-v', '--verbose', 'Be verbose.') { options[:verbose] = true }
|
71
|
-
|
72
|
-
return opt, options
|
73
|
-
end
|
74
|
-
|
75
|
-
def self.setup_pwd
|
76
|
-
options = {:default => false}
|
77
|
-
|
78
|
-
opt = OptionParser.new("#{File.basename($0)} pwd package1 [package2 ...]")
|
79
|
-
opt.on('--default', 'Show default db, ENV[\'MILKODE_DEFAULT_DIR\'] or ~/.milkode.') { options[:default] = true }
|
80
|
-
|
81
|
-
return opt, options
|
82
|
-
end
|
83
|
-
|
84
|
-
def self.setup_cleanup
|
85
|
-
options = {:verbose => false, :force => false}
|
86
|
-
|
87
|
-
opt = OptionParser.new("#{File.basename($0)} cleanup")
|
88
|
-
opt.on('-f', '--force', 'Force cleanup.') { options[:force] = true }
|
89
|
-
|
90
|
-
return opt, options
|
91
|
-
end
|
92
|
-
|
93
|
-
def self.setup_rebuild
|
94
|
-
options = {}
|
95
|
-
|
96
|
-
opt = OptionParser.new("#{File.basename($0)} keyword1 [keyword2 ...]")
|
97
|
-
opt.on('--all', 'Rebuild all.') { options[:all] = true}
|
98
|
-
opt.on('-v', '--verbose', 'Be verbose.') { options[:verbose] = true }
|
99
|
-
|
100
|
-
return opt, options
|
101
|
-
end
|
102
|
-
|
103
|
-
def self.setup_web
|
104
|
-
options = {
|
105
|
-
:environment => ENV['RACK_ENV'] || "development",
|
106
|
-
:pid => nil,
|
107
|
-
:Port => 9292,
|
108
|
-
:Host => "127.0.0.1",
|
109
|
-
:AccessLog => [],
|
110
|
-
:config => "config.ru",
|
111
|
-
# ----------------------------
|
112
|
-
:server => "thin",
|
113
|
-
:LaunchBrowser => true,
|
114
|
-
:DbDir => Milkode::CLI_Cdweb::select_dbdir,
|
115
|
-
}
|
116
|
-
|
117
|
-
opts = OptionParser.new("#{File.basename($0)} web")
|
118
|
-
opts.on('--db DB_DIR', 'Database dir (default : current_dir)') {|v| options[:DbDir] = v }
|
119
|
-
opts.on("-o", "--host HOST", "listen on HOST (default: 127.0.0.1)") {|host| options[:Host] = host }
|
120
|
-
opts.on('-p', '--port PORT', 'use PORT (default: 9292)') {|v| options[:Port] = v }
|
121
|
-
opts.on("-s", "--server SERVER", "serve using SERVER (default : thin)") {|s| options[:server] = s }
|
122
|
-
opts.on('-n', '--no-browser', 'No launch browser.') {|v| options[:LaunchBrowser] = false }
|
123
|
-
opts.on('--customize', 'Create customize file.') {|v| options[:customize] = true }
|
124
|
-
|
125
|
-
# --hostが'-h'を上書きするので、'-h'を再定義してあげる
|
126
|
-
opts.on_tail("-h", "-?", "--help", "Show this message") do
|
127
|
-
puts opts
|
128
|
-
exit
|
129
|
-
end
|
130
|
-
|
131
|
-
return opts, options
|
132
|
-
end
|
133
|
-
|
134
|
-
def self.setup_dir
|
135
|
-
options = {}
|
136
|
-
|
137
|
-
opt = OptionParser.new("#{File.basename($0)} dir")
|
138
|
-
opt.on('--top', 'XXX') {|v| options[:top] = true }
|
139
|
-
|
140
|
-
return opt, options
|
141
|
-
end
|
142
|
-
|
143
|
-
def self.setup_setdb
|
144
|
-
options = {}
|
145
|
-
|
146
|
-
opt = OptionParser.new("#{File.basename($0)} setdb")
|
147
|
-
opt.on('--default', '--reset', 'Reset default db.') {|v| options[:reset] = true }
|
148
|
-
|
149
|
-
return opt, options
|
150
|
-
end
|
151
|
-
|
152
|
-
def self.setup_mcd
|
153
|
-
options = {}
|
154
|
-
|
155
|
-
opt = OptionParser.new("#{File.basename($0)} mcd")
|
156
|
-
|
157
|
-
return opt, options
|
158
|
-
end
|
159
|
-
|
160
|
-
def self.setup_info
|
161
|
-
options = {}
|
162
|
-
|
163
|
-
opt = OptionParser.new("#{File.basename($0)} info")
|
164
|
-
|
165
|
-
return opt, options
|
166
|
-
end
|
167
|
-
|
168
|
-
def self.setup_ignore
|
169
|
-
bin = File.basename($0)
|
170
|
-
|
171
|
-
options = {}
|
172
|
-
|
173
|
-
opt = OptionParser.new("#{File.basename($0)} ignore [path ...]")
|
174
|
-
opt.on('-p PACKAGE', '--package PACKAGE', 'Specify ignore package.') {|v| options[:package] = v }
|
175
|
-
opt.on('-d', '--delete', 'Delete ignore') { options[:delete] = true }
|
176
|
-
opt.on('--delete-all', 'Delete all') { options[:delete_all] = true }
|
177
|
-
opt.on('--test', 'Ignore test, Display complete list') { options[:test] = true }
|
178
|
-
|
179
|
-
return opt, options
|
180
|
-
end
|
181
|
-
|
182
|
-
|
183
|
-
end
|
184
|
-
end
|
data/test/test_bin_exec.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
#
|
3
|
-
# @file
|
4
|
-
# @brief
|
5
|
-
# @author ongaeshi
|
6
|
-
# @date 2011/03/08
|
7
|
-
|
8
|
-
require 'rubygems'
|
9
|
-
require 'test/unit'
|
10
|
-
require 'milkode/cdstk/cli_cdstk'
|
11
|
-
|
12
|
-
class TestBinExec < Test::Unit::TestCase
|
13
|
-
def test_bin_exec
|
14
|
-
io = StringIO.new
|
15
|
-
|
16
|
-
# milk
|
17
|
-
Milkode::CLI_Cdstk.execute(io)
|
18
|
-
|
19
|
-
# 一定時間だけ起動するような仕組みは無いものか
|
20
|
-
# Milkode::CLI_Cdweb.execute(io, "--no-browser -p 5555".split)
|
21
|
-
|
22
|
-
# puts io.string
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|