lib/pushover/optparser.rb in pushover-0.1.2 vs lib/pushover/optparser.rb in pushover-0.2.0
- old
+ new
@@ -5,14 +5,15 @@
def initialize
super
@options = {}
on("-V", "--version", "Print version") { |version| @options[:version] = true}
- on("-t", "--token TOKEN", "Set your identity token.") { |o| @options[:token] = o}
- on("-a", "--app-key APPKEY", "Set the receiving application key.") { |o| @options[:appkey] = o}
- on("-m", "--message MESSAGE", "The message to be sent.") { |o| @options[:message] = o}
+ on("-u", "--user USER", "Which user, can be a saved name or token.") { |o| @options[:user] = o}
+ on("-a", "--app APPKEY", "Which app to notify, can be a saved name or apikey.") { |o| @options[:appkey] = o}
on("-T", "--title [TITLE]", "Set the title of the notification (optional).") { |o| @options[:title] = o}
+ on("--save-app NAME", "Saves the application to the config file under NAME.") { |o| @options[:save_app] = [@options[:appkey], o]}
+ on("--save-user NAME", "Saves the user to the config file under NAME.") { |o| @options[:save_user] = [@options[:user], o]}
end
# This will build an on/off option with a default value set to false.
def bool_on(word, description = "")
Options[word.to_sym] = false
@@ -31,11 +32,11 @@
end
# we need to mash in our config array. To do this we want to make config
# options that don't overwrite cli options.
Config.each do |k,v|
- @options[k] = v if !@options[k]
+ @options[k] = v if !@options[k] && ["applications", "users"].include?(k)
end
end
def [](k = nil)
return @options[k] if k
@@ -43,9 +44,13 @@
nil
end
def []=(k,v)
@options[k] = v
+ end
+
+ def empty?
+ @options.empty?
end
end
Options = OptionParser.new
end