Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- require 'washbullet'
- require 'thor'
- class CommandCLI < Thor
- desc "pushbullet COMMAND", "Runs the given COMMAND and sends a pushbullet notification if the exit status is non-zero"
- long_desc <<-DESC
- Runs the given command and sends a pushbullet notification if the exit status is non-zero.
- The message can be customized, and there are a few values that you can use through placeholders, eg:
- The command %{command} returned %{status}: %{result}
- Available keys for the message:
- - command
- - status
- - result
- DESC
- option :message, default: "The command %{command} returned %{status}!\n%{result}"
- option :title, default: "Notifatron"
- option :key, default: ENV['PUSHBULLET_KEY']
- def pushbullet command
- if options[:key].nil?
- raise ArgumentError.new("Need to specify the pushbullet key in the environment as PUSHBULLET_KEY")
- end
- pushbullet_client = Washbullet::Client.new(options[:key])
- res = {
- command: command,
- result: system(command),
- status: $?.exitstatus
- }
- if res[:status] != 0
- message = options[:message] % res
- #puts "Would push notification: #{ options[:title] } - #{ message }"
- pushbullet_client.push_note nil, options[:title], message
- end
- end
- end
- CommandCLI.start(ARGV)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement