Sha256: 27b6143429520f8fd0c88ef66731ebaf2d2abae0d73dce5d57082910e97b3d71

Contents?: true

Size: 1.23 KB

Versions: 1

Compression:

Stored size: 1.23 KB

Contents

#!/usr/bin/env ruby
require 'gli'
require 'imessage'

include GLI::App

program_desc 'Command line tool to send iMessage.'

version Imessage::VERSION

desc 'Send iMessage'
long_desc <<-EOS
Example: $ imessage send "hello" --to "foo@example.com" --attachment 'oh.png'
EOS

command :send do |c|
  c.desc 'Contacts'
  c.flag [:to, :contacts], type: Array
  c.flag [:a, :attachment], type: String

  c.action do |global_options, options, args|
    help_now!('Message or Attachment is required') if !options[:attachment] && args.empty?
    help_now!('Contacts is required') unless options[:contacts]

    attachment = options[:attachment]
    if File.exists?(attachment)
      attachment = File.expand_path(attachment)
    else
      exit_now!("Can not find file #{attachment}")
    end

    sender = Imessage::Sender.new
    sender.deliver(
      text: args.first,
      attachment: attachment,
      contacts: options[:contacts]
    )
  end
end

pre do |global,command,options,args|
  true
end

post do |global,command,options,args|
  # Post logic here
  # Use skips_post before a command to skip this
  # block on that command only
end

on_error do |exception|
  # Error logic here
  # return false to skip default error handling
  true
end

exit run(ARGV)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
imessage-0.1.0 bin/imessage