Class: WPOptionParser

Inherits:
Object
  • Object
show all
Defined in:
lib/publishing/wp_options.rb

Class Method Summary collapse

Class Method Details

.parse(args) {|options| ... } ⇒ Object

Yields:

  • (options)


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/publishing/wp_options.rb', line 25

def self.parse(args)
	options = OpenStruct.new
	options.tags = []
	options.title = nil
	options.type = 'html'
	options.bluxrc = nil
	options.command = :post
	options.entry_id = nil

	opts = OptionParser.new
	opts.banner = "Usage: post.rb [options]"
	opts.separator ""
	opts.separator "options :"

	opts.on("-c", "--categories {list}", "comma separated list of tags/categories") do |v|
		options.tags = v.split ","
	end

	opts.on("-t", "--title {title}", "title for the post") do |v|
		options.title = v
	end

	opts.on("-T", "--type {html|xhtml|text}", 
			"type of the content. ('html' is the default).") do |v|
		options.type = v
		end

	opts.on("--config {config_file}", "blux config file path") do |f|
		options.bluxrc = f
	end

	opts.on("--update {entry_id}", "update an existing post") do |id|
		options.command = :put
		options.entry_id = id
	end

	opts.on("--delete {entry_id}", "delete an existing post") do |id|
		options.command = :delete
		options.entry_id = id
	end

	opts.on("-h", "--help",	"displays this help") do
		puts
		puts opts.to_s
		puts
		exit 0
	end

	opts.parse!(args)
	yield options
end