Skip to content

Commit 8cfeccd

Browse files
committed
278 #92 automatic-command merge into automatic command
1 parent 2ab951a commit 8cfeccd

File tree

3 files changed

+109
-132
lines changed

3 files changed

+109
-132
lines changed

bin/automatic

Lines changed: 99 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,108 @@
33
# Name:: Automatic::Ruby
44
# Author:: 774 <http://id774.net>
55
# Created:: Feb 18, 2012
6-
# Updated:: Jan 22, 2013
7-
# Copyright:: 774 Copyright (c) 2012
6+
# Updated:: Mar 19, 2013
7+
# Copyright:: 774 Copyright (c) 2012-2013
88
# License:: Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0.
99

1010
root_dir = File.expand_path("..", File.dirname(__FILE__))
1111
$:.unshift root_dir
1212
$:.unshift root_dir + '/lib'
13+
1314
require 'automatic'
15+
require 'rubygems'
1416
require 'optparse'
17+
require 'fileutils'
18+
require 'feedbag'
19+
require 'pp'
1520

1621
recipe_path = ""
17-
parser = OptionParser.new { |parser|
22+
23+
def abort_with_usage(subcommand, message)
24+
top_filename = File.basename($0)
25+
abort("Usage: #{top_filename} #{subcommand} #{message}")
26+
end
27+
28+
subparsers = {
29+
'scaffold' => lambda {|argv|
30+
Dir::entries(root_dir + '/plugins').sort.each {|path|
31+
dir = (File.expand_path('~/.automatic/plugins/' + path))
32+
unless File.exist?(dir)
33+
FileUtils.mkdir_p(dir)
34+
puts "Creating #{dir}"
35+
end
36+
}
37+
dir = (File.expand_path('~/.automatic/assets'))
38+
unless File.exist?(dir)
39+
FileUtils.mkdir_p(dir)
40+
FileUtils.cp_r(root_dir + '/assets/siteinfo', dir + '/siteinfo')
41+
puts "Creating #{dir}"
42+
end
43+
dir = (File.expand_path('~/.automatic/config'))
44+
unless File.exist?(dir)
45+
FileUtils.mkdir_p(dir)
46+
FileUtils.cp_r(root_dir + '/config', dir + '/example')
47+
puts "Creating #{dir}"
48+
end
49+
dir = (File.expand_path('~/.automatic/db'))
50+
unless File.exist?(dir)
51+
FileUtils.mkdir_p(dir)
52+
puts "Creating #{dir}"
53+
end
54+
},
55+
'unscaffold' => lambda {|argv|
56+
dir = (File.expand_path('~/.automatic'))
57+
if File.directory?(dir)
58+
puts "Removing #{dir}"
59+
FileUtils.rm_r(dir)
60+
end
61+
},
62+
'autodiscovery' => lambda {|argv|
63+
url = argv.shift || abort_with_usage("autodiscovery", "<url>")
64+
pp Feedbag.find(url)
65+
},
66+
'feedparser' => lambda {|argv|
67+
require 'automatic/feed_parser'
68+
url = argv.shift || abort_with_usage("feedparser", "<url>")
69+
rss_results = Automatic::FeedParser.get(url)
70+
pp rss_results
71+
},
72+
'inspect' => lambda {|argv|
73+
require 'automatic/feed_parser'
74+
url = argv.shift || abort_with_usage("inspect", "<url>")
75+
feeds = Feedbag.find(url)
76+
pp feeds
77+
rss_results = Automatic::FeedParser.get(feeds.pop)
78+
pp rss_results
79+
},
80+
'opmlparser' => lambda {|argv|
81+
require 'automatic/opml'
82+
path = argv.shift
83+
if path.nil?
84+
abort_with_usage("opmlparser", "<opml path>")
85+
end
86+
parser = Automatic::OPML::Parser.new(File.read(path))
87+
parser.each_outline {|opml, o|
88+
puts "#{o.xmlUrl}"
89+
}
90+
},
91+
'log' => lambda {|argv|
92+
require 'automatic/log'
93+
level = argv.shift || abort_with_usage("log", "<level> <message>")
94+
message = ARGV.shift
95+
Automatic::Log.puts(level, message)
96+
}
97+
}
98+
99+
parser = OptionParser.new {|parser|
18100
parser.banner = "Usage: automatic [options] arg"
19101
parser.version = Automatic.const_get(:VERSION)
20-
parser.separator "options:"
102+
parser.separator "Args: #{subparsers.keys.join(", ")}"
103+
parser.separator "Options:"
21104
parser.on('-c', '--config FILE', String,
22105
"recipe YAML file"){|c| recipe_path = c}
23106
parser.on('-h', '--help', "show this message") {
107+
24108
puts parser
25109
exit
26110
}
@@ -35,15 +119,19 @@ rescue OptionParser::ParseError => err
35119
exit 1
36120
end
37121

38-
if recipe_path.to_s.empty?
39-
if ENV["AUTOMATIC_RUBY_ENV"] == "test"
40-
recpie_path = File.join(root_dir, 'config/default.yml')
122+
unless recipe_path.to_s.empty?
123+
recipe = Automatic::Recipe.new(recipe_path)
124+
Automatic.run(:recipe => recipe,
125+
:root_dir => root_dir)
126+
else
127+
parser.order!(ARGV)
128+
unless ARGV.empty?
129+
Hash.new {|h, k|
130+
puts "No such subcommand: #{k}"
131+
exit 1
132+
}.update(subparsers)[ARGV.shift].call(ARGV)
41133
else
42134
puts parser
43135
exit 0
44136
end
45137
end
46-
47-
recipe = Automatic::Recipe.new(recipe_path)
48-
Automatic.run(:recipe => recipe,
49-
:root_dir => root_dir)

bin/automatic-config

Lines changed: 0 additions & 111 deletions
This file was deleted.

script/build

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ kickstart() {
2121
export RACK_ENV="test"
2222
export DATABASE_URL="$RACK_ROOT/db"
2323
ruby -v
24-
test_config log info started.
24+
test_subcommand log info started.
2525
}
2626

2727
exec_rspec() {
@@ -34,7 +34,7 @@ run_test() {
3434
while [ $# -gt 0 ]
3535
do
3636
$RACK_ROOT/bin/automatic -c $1
37-
test_config log info $?
37+
test_subcommand log info $?
3838
shift
3939
done
4040
}
@@ -47,21 +47,21 @@ load_tests() {
4747
unset YAML_FILE
4848
}
4949

50-
test_config() {
51-
$RACK_ROOT/bin/automatic-config $*
50+
test_subcommand() {
51+
$RACK_ROOT/bin/automatic $*
5252
}
5353

5454
test_scaffold() {
55-
test_config scaffold
56-
test_config unscaffold
55+
test_subcommand scaffold
56+
test_subcommand unscaffold
5757
}
5858

5959
added_tests() {
6060
test -f $HOME/.automatic || test_scaffold
61-
test_config autodiscovery http://blog.id774.net/blogs/
62-
test_config opmlparser "$RACK_ROOT/test/fixtures/sampleOPML.xml"
63-
test_config feedparser http://blog.id774.net/blogs/feed/ > /dev/null
64-
test_config log info finished.
61+
test_subcommand autodiscovery http://blog.id774.net/blogs/
62+
test_subcommand opmlparser "$RACK_ROOT/test/fixtures/sampleOPML.xml"
63+
test_subcommand feedparser http://blog.id774.net/blogs/feed/ > /dev/null
64+
test_subcommand log info finished.
6565
}
6666

6767
integration() {

0 commit comments

Comments
 (0)