Class: CLI

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

Class Method Summary collapse

Class Method Details

.startObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/cli.rb', line 6

def self.start
    options = {}
    OptionParser.new do |opts|
        opts.banner = "Usage: slack-cli-webhook [options]"

        opts.on("-m MESSAGE", "--message MESSAGE", "Message to send") do |m|
            options[:message] = m
        end

        opts.on("-w WEBHOOK", "--webhook WEBHOOK", "Webhook to send to") do |w|
            options[:webhook] = w
        end

    end.parse!

    if !options.key?(:message)
        puts "Required attribute missing: #{:message}\nAdd -h or --help to view the usage"
        exit
    end

    if !options.key?(:webhook)
        puts "Required attribute missing: #{:webhook}\nAdd -h or --help to view the usage"
        exit
    end

    if SlackCliWebhook.send_message(options[:message], options[:webhook])
        puts "Message sent successfully."
        exit
    else
        puts "Sending message failed, please try again later."
        exit
    end
end