Class: BluxOptionParser

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

Class Method Summary collapse

Class Method Details

.parse(args) ⇒ Object



23
24
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/blux_option_parser.rb', line 23

def self.parse(args)
	options = OpenStruct.new
	options.verbose = false
	options.list_preview = false
	options.list_details = false

	opts = OptionParser.new do |opts|
		opts.banner = "Usage: blux <command> [options] [attributes]"

		opts.on("-n", "--new", "create a new draft") do 
			options.command = :new
		end

		opts.on("-e", "--edit", "edit a draft") do
			options.command = :edit
		end

		opts.on("-l", "--list", "list drafts") do
			options.command = :list
		end

		opts.on("-s", "--set", "set an attribute on a draft") do
			options.command = :set
		end
		
		opts.on("--unset ATTR", "delete an attribute on a draft") do |attr|
			options.command = :unset
			options.attribute = attr
		end

		opts.on("-c", "--convert", "convert a draft to html") do
			options.command = :convert
		end

		opts.on("-o", "--out", "dump the content of a draft to stdout") do
			options.command = :out
		end

		opts.on("-p", "--publish", "publish a draft") do
			options.command = :publish
		end

		opts.on("-u", "--update", "update a draft") do
			options.command = :update
		end

		opts.on("-d", "--delete", "mark a draft as deleted") do
			options.command = :delete
		end

		opts.on("--latest", "work on the latest draft") do
			options.use_latest = true
		end

		opts.on("--title TITLE", "work on a draft with title") do |title|
			options.use_title = true
			options.title = title
		end

		opts.on("-f", "--file FILENAME", "work on a specific draft file") do |filename|
			options.filename = filename
		end

		opts.on("--set_edit_url", "sets the edit url, given after publishing") do
			options.command = :set_edit_url
		end

		opts.on("--post-cmd", "shows post publishing info: request & response") do
			options.command = :show_post_info
		end

		opts.on("--with-preview", "show a preview of each draft while listing") do
			options.list_preview = true
		end

		opts.on("--details", "show all attributes when listing") do
			options.list_details = true
		end

		opts.on("--verbose", "verbose mode") do
			options.verbose = true
		end

		opts.on("--version", "print version information") do
			options.command = :version
		end

		opts.on_tail("-h", "--help", "show this message") do
			puts opts
			exit
		end
	end

	opts.parse!(args)

	options.attributes = args
	options
end