Sha256: 35a6a8cadcc86f0171d5be53615629266856d5b5b43d3727180930f14fa58d3f

Contents?: true

Size: 1.57 KB

Versions: 3

Compression:

Stored size: 1.57 KB

Contents

#!/usr/bin/env ruby

# frozen_string_literal: true

require 'dotenv'
require 'optparse'
require 'ostruct'

require_relative '../lib/secretsanta'

Dotenv.load

begin
  options = OpenStruct.new

  options.twilio_account_sid = ENV['TWILIO_ACCOUNT_SID']
  options.twilio_auth_token = ENV['TWILIO_AUTH_TOKEN']
  options.from_number = ENV['TWILIO_PHONE_NUMBER']
  options.dry_run = ENV['ENVIRONMENT'] == 'TEST'
  options.participants = nil

  opt_parser = OptionParser.new do |opts|
    opts.banner = SecretSanta.help_text

    opts.on('-h', '--help', 'Show this help message') do
      puts opts
      exit 0
    end

    opts.on('-a', '--twilio-account-sid=SID', 'Twilio AccountSID') do |sid|
      options.twilio_account_sid = sid
    end

    opts.on('-t', '--twilio-auth-token=TOKEN', 'Twilio authentication token') do |token|
      options.twilio_auth_token = token
    end

    opts.on('-f', '--from_number=NUM', 'Twilio phone number') do |num|
      options.from_number = num
    end

    opts.on('-p', '--participants=JSON_FILE', 'JSON file with participants') do |participants_file|
      options.participants = JSON.parse(File.read(participants_file), symbolize_names: true)[:participants]
    rescue StandardError => e
      puts e
      exit 1
    end
  end

  opt_parser.parse!(ARGV)

  raise OptionParser::MissingArgument if options.to_h.values.any?(&:nil?)

  begin
    puts SecretSanta.notify_participants!(options)
  rescue SecretSanta::Error => e
    puts e
    exit 1
  end
rescue OptionParser::MissingArgument
  puts "All options are required, see help below:\n\n"
  puts opt_parser.help
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
secretsanta-1.0.3 bin/secretsanta
secretsanta-1.0.2 bin/secretsanta
secretsanta-1.0.1 bin/secretsanta