1 # Copyright 2008 Dag Odenhall <dag.odenhall@gmail.com>
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
19 # Parse and manage command line options
25 @options[:config] = "#{ENV["HOME"]}/.amazing/config.yml"
26 @options[:loglevel] = "info"
27 @options[:include] = []
28 @options[:autoinclude] = true
29 @options[:update] = []
31 @parser = OptionParser.new do |opts|
32 opts.on("-c", "--config FILE", "Configuration file (~/.amazing/config.yml)") do |config|
33 @options[:config] = config
35 opts.on("-l", "--log-level LEVEL", "Severity threshold (info)") do |level|
36 @options[:loglevel] = level
38 opts.on("-s", "--stop", "Stop the running amazing process") do
39 @options[:stop] = true
41 opts.on("-i", "--include SCRIPT", "Include a widgets script") do |script|
42 @options[:include] << script
44 opts.on("--no-auto-include", "Don't auto include from ~/.amazing/widgets/") do
45 @options[:autoinclude] = false
47 opts.on("-u", "--update [WIDGET]", "Update a widget and exit") do |widget|
49 @options[:update] << widget
51 @options[:update] = :all
54 opts.on("-w", "--list-widgets [WIDGET]", "List available widgets or options and fields for a widget") do |widget|
55 @options[:listwidgets] = widget || true
57 opts.on("-t", "--test-widget WIDGET [OPTIONS]", "Dump field values for a widget configured with inline YAML") do |widget|
58 @options[:test] = widget
60 opts.on("-h", "--help", "You're looking at it") do
61 @options[:help] = true
67 @options.keys.each do |key|
84 def []=(option, value)
85 @options[option] = value