wpb 0.0.3 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog.md +9 -3
- data/bin/wpb +3 -5
- data/doc/Bash.html +222 -0
- data/doc/Comment.html +411 -0
- data/doc/Gemfile.html +110 -0
- data/doc/Page.html +315 -0
- data/doc/PagePost.html +422 -0
- data/doc/Post.html +164 -0
- data/doc/Rakefile.html +107 -0
- data/doc/Setting.html +164 -0
- data/doc/User.html +415 -0
- data/doc/WPB.html +188 -0
- data/doc/WPB/AddType.html +254 -0
- data/doc/WPB/App.html +231 -0
- data/doc/bin/wpb.html +54 -0
- data/doc/created.rid +13 -0
- data/doc/index.html +114 -0
- data/doc/lib/wpb/bash_rb.html +56 -0
- data/doc/lib/wpb/comment_rb.html +54 -0
- data/doc/lib/wpb/page_rb.html +203 -0
- data/doc/lib/wpb/pagepost_rb.html +54 -0
- data/doc/lib/wpb/post_rb.html +52 -0
- data/doc/lib/wpb/setting_rb.html +54 -0
- data/doc/lib/wpb/user_rb.html +54 -0
- data/doc/lib/wpb/version_rb.html +52 -0
- data/doc/lib/wpb_rb.html +68 -0
- data/doc/rdoc.css +706 -0
- data/lib/wpb.rb +36 -29
- data/lib/wpb/bash.rb +18 -0
- data/lib/wpb/clamp/attribute.rb +37 -0
- data/lib/wpb/clamp/attribute_declaration.rb +40 -0
- data/lib/wpb/clamp/command.rb +137 -0
- data/lib/wpb/clamp/errors.rb +26 -0
- data/lib/wpb/clamp/help.rb +69 -0
- data/lib/wpb/clamp/option.rb +77 -0
- data/lib/wpb/clamp/option/declaration.rb +58 -0
- data/lib/wpb/clamp/option/parsing.rb +45 -0
- data/lib/wpb/clamp/parameter.rb +70 -0
- data/lib/wpb/clamp/parameter/declaration.rb +28 -0
- data/lib/wpb/clamp/parameter/parsing.rb +28 -0
- data/lib/wpb/clamp/subcommand.rb +23 -0
- data/lib/wpb/clamp/subcommand/declaration.rb +40 -0
- data/lib/wpb/clamp/subcommand/execution.rb +37 -0
- data/lib/wpb/clamp/version.rb +3 -0
- data/lib/wpb/comment.rb +51 -5
- data/lib/wpb/page.rb +46 -0
- data/lib/wpb/pagepost.rb +29 -16
- data/lib/wpb/user.rb +25 -0
- data/lib/wpb/version.rb +4 -1
- metadata +43 -2
data/lib/wpb.rb
CHANGED
@@ -7,41 +7,48 @@ require "wpb/post"
|
|
7
7
|
require "wpb/comment"
|
8
8
|
require "active_record"
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
:socket => "/Applications/MAMP/tmp/mysql/mysql.sock", #/tmp/mysql.sock
|
13
|
-
:host => "localhost",
|
14
|
-
:username => "root",
|
15
|
-
:password => "root",
|
16
|
-
:database => "wordpress"
|
17
|
-
}
|
10
|
+
##
|
11
|
+
# The wrapper for the wpb gem
|
18
12
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
13
|
+
module WPB
|
14
|
+
class AddType < ActiveRecord::Migration
|
15
|
+
def self.up
|
16
|
+
suppress_messages do
|
17
|
+
unless column_exists? :wp_posts, :type
|
18
|
+
add_column :wp_posts, :type, :string
|
19
|
+
PagePost.reset_column_information
|
20
|
+
end
|
27
21
|
end
|
28
22
|
end
|
23
|
+
|
24
|
+
def self.down
|
25
|
+
remove_column :wp_posts, :type
|
26
|
+
end
|
29
27
|
end
|
30
28
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
29
|
+
class App
|
30
|
+
def self.run
|
31
|
+
config = {
|
32
|
+
:adapter => "mysql",
|
33
|
+
:socket => "/Applications/MAMP/tmp/mysql/mysql.sock", #/tmp/mysql.sock
|
34
|
+
:host => "localhost",
|
35
|
+
:username => "root",
|
36
|
+
:password => "root",
|
37
|
+
:database => "wordpress"
|
38
|
+
}
|
35
39
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
40
|
+
ActiveRecord::Base.establish_connection(config)
|
41
|
+
|
42
|
+
AddType::up
|
43
|
+
PagePost.all.each do |p|
|
44
|
+
p.type = p.post_type.capitalize
|
45
|
+
if p.post_type != "post" && p.post_type != "page"
|
46
|
+
p.type = "Post"
|
47
|
+
end
|
48
|
+
p.save
|
49
|
+
end
|
50
|
+
end
|
41
51
|
end
|
42
|
-
p.save
|
43
52
|
end
|
44
53
|
|
45
|
-
|
46
|
-
|
47
|
-
end
|
54
|
+
WPB::App::run
|
data/lib/wpb/bash.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "wpb/clamp/command"
|
2
|
+
|
3
|
+
class Bash < Clamp::Command
|
4
|
+
option ["-v", "--version"], :flag, "print version"
|
5
|
+
|
6
|
+
def execute
|
7
|
+
if version?
|
8
|
+
require "wpb/version"
|
9
|
+
print "WordPress Bash #{WPB::VERSION} (c) James Birtles"
|
10
|
+
else
|
11
|
+
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
12
|
+
libs = " -r irb/completion"
|
13
|
+
libs << " -r #{File.expand_path('../../wpb.rb', __FILE__)}"
|
14
|
+
puts "Connecting to database..."
|
15
|
+
exec "#{irb} #{libs}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Clamp
|
2
|
+
|
3
|
+
class Attribute
|
4
|
+
|
5
|
+
attr_reader :description, :attribute_name, :default_value
|
6
|
+
|
7
|
+
def help_rhs
|
8
|
+
rhs = description
|
9
|
+
if defined?(@default_value)
|
10
|
+
rhs += " (default: #{@default_value.inspect})"
|
11
|
+
end
|
12
|
+
rhs
|
13
|
+
end
|
14
|
+
|
15
|
+
def help
|
16
|
+
[help_lhs, help_rhs]
|
17
|
+
end
|
18
|
+
|
19
|
+
def ivar_name
|
20
|
+
"@#{attribute_name}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def read_method
|
24
|
+
attribute_name
|
25
|
+
end
|
26
|
+
|
27
|
+
def default_method
|
28
|
+
"default_#{read_method}"
|
29
|
+
end
|
30
|
+
|
31
|
+
def write_method
|
32
|
+
"#{attribute_name}="
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Clamp
|
2
|
+
|
3
|
+
module AttributeDeclaration
|
4
|
+
|
5
|
+
protected
|
6
|
+
|
7
|
+
def define_accessors_for(attribute, &block)
|
8
|
+
define_reader_for(attribute)
|
9
|
+
define_default_for(attribute)
|
10
|
+
define_writer_for(attribute, &block)
|
11
|
+
end
|
12
|
+
|
13
|
+
def define_reader_for(attribute)
|
14
|
+
define_method(attribute.read_method) do
|
15
|
+
if instance_variable_defined?(attribute.ivar_name)
|
16
|
+
instance_variable_get(attribute.ivar_name)
|
17
|
+
elsif respond_to?(attribute.default_method)
|
18
|
+
send(attribute.default_method)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def define_default_for(attribute)
|
24
|
+
define_method(attribute.default_method) do
|
25
|
+
attribute.default_value
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def define_writer_for(attribute, &block)
|
30
|
+
define_method(attribute.write_method) do |value|
|
31
|
+
if block
|
32
|
+
value = instance_exec(value, &block)
|
33
|
+
end
|
34
|
+
instance_variable_set(attribute.ivar_name, value)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
require 'clamp/errors'
|
2
|
+
require 'clamp/help'
|
3
|
+
require 'clamp/option/declaration'
|
4
|
+
require 'clamp/option/parsing'
|
5
|
+
require 'clamp/parameter/declaration'
|
6
|
+
require 'clamp/parameter/parsing'
|
7
|
+
require 'clamp/subcommand/declaration'
|
8
|
+
require 'clamp/subcommand/execution'
|
9
|
+
|
10
|
+
module Clamp
|
11
|
+
|
12
|
+
# {Command} models a shell command. Each command invocation is a new object.
|
13
|
+
# Command options and parameters are represented as attributes
|
14
|
+
# (see {Command::Declaration}).
|
15
|
+
#
|
16
|
+
# The main entry-point is {#run}, which uses {#parse} to populate attributes based
|
17
|
+
# on an array of command-line arguments, then calls {#execute} (which you provide)
|
18
|
+
# to make it go.
|
19
|
+
#
|
20
|
+
class Command
|
21
|
+
|
22
|
+
# Create a command execution.
|
23
|
+
#
|
24
|
+
# @param [String] invocation_path the path used to invoke the command
|
25
|
+
# @param [Hash] context additional data the command may need
|
26
|
+
#
|
27
|
+
def initialize(invocation_path, context = {})
|
28
|
+
@invocation_path = invocation_path
|
29
|
+
@context = context
|
30
|
+
end
|
31
|
+
|
32
|
+
# @return [String] the path used to invoke this command
|
33
|
+
#
|
34
|
+
attr_reader :invocation_path
|
35
|
+
|
36
|
+
# @return [Array<String>] unconsumed command-line arguments
|
37
|
+
#
|
38
|
+
def remaining_arguments
|
39
|
+
@remaining_arguments
|
40
|
+
end
|
41
|
+
|
42
|
+
# Parse command-line arguments.
|
43
|
+
#
|
44
|
+
# @param [Array<String>] arguments command-line arguments
|
45
|
+
# @return [Array<String>] unconsumed arguments
|
46
|
+
#
|
47
|
+
def parse(arguments)
|
48
|
+
@remaining_arguments = arguments.dup
|
49
|
+
parse_options
|
50
|
+
parse_parameters
|
51
|
+
@remaining_arguments
|
52
|
+
end
|
53
|
+
|
54
|
+
# Run the command, with the specified arguments.
|
55
|
+
#
|
56
|
+
# This calls {#parse} to process the command-line arguments,
|
57
|
+
# then delegates to {#execute}.
|
58
|
+
#
|
59
|
+
# @param [Array<String>] arguments command-line arguments
|
60
|
+
#
|
61
|
+
def run(arguments)
|
62
|
+
parse(arguments)
|
63
|
+
execute
|
64
|
+
execute_subcommands
|
65
|
+
end
|
66
|
+
|
67
|
+
# Execute the command (assuming that all options/parameters have been set).
|
68
|
+
#
|
69
|
+
# This method is designed to be overridden in sub-classes.
|
70
|
+
#
|
71
|
+
def execute
|
72
|
+
raise "you need to define #execute"
|
73
|
+
end
|
74
|
+
|
75
|
+
def execute_subcommands
|
76
|
+
if self.class.has_subcommands?
|
77
|
+
execute_subcommand
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# @return [String] usage documentation for this command
|
82
|
+
#
|
83
|
+
def help
|
84
|
+
self.class.help(invocation_path)
|
85
|
+
end
|
86
|
+
|
87
|
+
include Clamp::Option::Parsing
|
88
|
+
include Clamp::Parameter::Parsing
|
89
|
+
include Clamp::Subcommand::Execution
|
90
|
+
|
91
|
+
protected
|
92
|
+
|
93
|
+
attr_accessor :context
|
94
|
+
|
95
|
+
private
|
96
|
+
|
97
|
+
def signal_usage_error(message)
|
98
|
+
e = UsageError.new(message, self)
|
99
|
+
e.set_backtrace(caller)
|
100
|
+
raise e
|
101
|
+
end
|
102
|
+
|
103
|
+
def help_requested=(value)
|
104
|
+
raise Clamp::HelpWanted.new(self)
|
105
|
+
end
|
106
|
+
|
107
|
+
class << self
|
108
|
+
|
109
|
+
include Clamp::Option::Declaration
|
110
|
+
include Clamp::Parameter::Declaration
|
111
|
+
include Clamp::Subcommand::Declaration
|
112
|
+
include Help
|
113
|
+
|
114
|
+
# Create an instance of this command class, and run it.
|
115
|
+
#
|
116
|
+
# @param [String] invocation_path the path used to invoke the command
|
117
|
+
# @param [Array<String>] arguments command-line arguments
|
118
|
+
# @param [Hash] context additional data the command may need
|
119
|
+
#
|
120
|
+
def run(invocation_path = File.basename($0), arguments = ARGV, context = {})
|
121
|
+
begin
|
122
|
+
new(invocation_path, context).run(arguments)
|
123
|
+
rescue Clamp::UsageError => e
|
124
|
+
$stderr.puts "ERROR: #{e.message}"
|
125
|
+
$stderr.puts ""
|
126
|
+
$stderr.puts "See: '#{e.command.invocation_path} --help'"
|
127
|
+
exit(1)
|
128
|
+
rescue Clamp::HelpWanted => e
|
129
|
+
puts e.command.help
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Clamp
|
2
|
+
|
3
|
+
class Error < StandardError
|
4
|
+
|
5
|
+
def initialize(message, command)
|
6
|
+
super(message)
|
7
|
+
@command = command
|
8
|
+
end
|
9
|
+
|
10
|
+
attr_reader :command
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
# raise to signal incorrect command usage
|
15
|
+
class UsageError < Error; end
|
16
|
+
|
17
|
+
# raise to request usage help
|
18
|
+
class HelpWanted < Error
|
19
|
+
|
20
|
+
def initialize(command)
|
21
|
+
super("I need help", command)
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'stringio'
|
2
|
+
|
3
|
+
module Clamp
|
4
|
+
|
5
|
+
module Help
|
6
|
+
|
7
|
+
def usage(usage)
|
8
|
+
@declared_usage_descriptions ||= []
|
9
|
+
@declared_usage_descriptions << usage
|
10
|
+
end
|
11
|
+
|
12
|
+
attr_reader :declared_usage_descriptions
|
13
|
+
|
14
|
+
def description=(description)
|
15
|
+
@description = description.dup
|
16
|
+
if @description =~ /^\A\n*( +)/
|
17
|
+
indent = $1
|
18
|
+
@description.gsub!(/^#{indent}/, '')
|
19
|
+
end
|
20
|
+
@description.strip!
|
21
|
+
end
|
22
|
+
|
23
|
+
attr_reader :description
|
24
|
+
|
25
|
+
def derived_usage_description
|
26
|
+
parts = parameters.map { |a| a.name }
|
27
|
+
parts.unshift("[OPTIONS]") if has_options?
|
28
|
+
parts.join(" ")
|
29
|
+
end
|
30
|
+
|
31
|
+
def usage_descriptions
|
32
|
+
declared_usage_descriptions || [derived_usage_description]
|
33
|
+
end
|
34
|
+
|
35
|
+
def help(invocation_path)
|
36
|
+
help = StringIO.new
|
37
|
+
help.puts "Usage:"
|
38
|
+
usage_descriptions.each_with_index do |usage, i|
|
39
|
+
help.puts " #{invocation_path} #{usage}".rstrip
|
40
|
+
end
|
41
|
+
if description
|
42
|
+
help.puts ""
|
43
|
+
help.puts description.gsub(/^/, " ")
|
44
|
+
end
|
45
|
+
detail_format = " %-29s %s"
|
46
|
+
if has_parameters?
|
47
|
+
help.puts "\nParameters:"
|
48
|
+
parameters.each do |parameter|
|
49
|
+
help.puts detail_format % parameter.help
|
50
|
+
end
|
51
|
+
end
|
52
|
+
if has_subcommands?
|
53
|
+
help.puts "\nSubcommands:"
|
54
|
+
recognised_subcommands.each do |subcommand|
|
55
|
+
help.puts detail_format % subcommand.help
|
56
|
+
end
|
57
|
+
end
|
58
|
+
if has_options?
|
59
|
+
help.puts "\nOptions:"
|
60
|
+
recognised_options.each do |option|
|
61
|
+
help.puts detail_format % option.help
|
62
|
+
end
|
63
|
+
end
|
64
|
+
help.string
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'clamp/attribute'
|
2
|
+
|
3
|
+
module Clamp
|
4
|
+
|
5
|
+
class Option < Attribute
|
6
|
+
|
7
|
+
def initialize(switches, type, description, options = {})
|
8
|
+
@switches = Array(switches)
|
9
|
+
@type = type
|
10
|
+
@description = description
|
11
|
+
if options.has_key?(:attribute_name)
|
12
|
+
@attribute_name = options[:attribute_name].to_s
|
13
|
+
end
|
14
|
+
if options.has_key?(:default)
|
15
|
+
@default_value = options[:default]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
attr_reader :switches, :type
|
20
|
+
|
21
|
+
def attribute_name
|
22
|
+
@attribute_name ||= long_switch.sub(/^--(\[no-\])?/, '').tr('-', '_')
|
23
|
+
end
|
24
|
+
|
25
|
+
def long_switch
|
26
|
+
switches.find { |switch| switch =~ /^--/ }
|
27
|
+
end
|
28
|
+
|
29
|
+
def handles?(switch)
|
30
|
+
recognised_switches.member?(switch)
|
31
|
+
end
|
32
|
+
|
33
|
+
def flag?
|
34
|
+
@type == :flag
|
35
|
+
end
|
36
|
+
|
37
|
+
def flag_value(switch)
|
38
|
+
!(switch =~ /^--no-(.*)/ && switches.member?("--\[no-\]#{$1}"))
|
39
|
+
end
|
40
|
+
|
41
|
+
def read_method
|
42
|
+
if flag?
|
43
|
+
super + "?"
|
44
|
+
else
|
45
|
+
super
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def extract_value(switch, arguments)
|
50
|
+
if flag?
|
51
|
+
flag_value(switch)
|
52
|
+
else
|
53
|
+
arguments.shift
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def help_lhs
|
58
|
+
lhs = switches.join(", ")
|
59
|
+
lhs += " " + type unless flag?
|
60
|
+
lhs
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def recognised_switches
|
66
|
+
switches.map do |switch|
|
67
|
+
if switch =~ /^--\[no-\](.*)/
|
68
|
+
["--#{$1}", "--no-#{$1}"]
|
69
|
+
else
|
70
|
+
switch
|
71
|
+
end
|
72
|
+
end.flatten
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|