lib/rumble/cli.rb in rumble-0.5.3 vs lib/rumble/cli.rb in rumble-0.6.0

- old
+ new

@@ -1,8 +1,8 @@ # frozen_string_literal: true -# Copyright (c) 2018-2019 Yegor Bugayenko +# Copyright (c) 2018-2020 Yegor Bugayenko # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the 'Software'), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell @@ -18,22 +18,24 @@ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +require 'English' require 'mail' require 'uuidtools' require 'liquid' require 'csv' +require 'tmpdir' require 'redcarpet' require 'redcarpet/render_strip' require 'rainbow' require_relative 'version' # Rumble main script. # Author:: Yegor Bugayenko (yegor256@gmail.com) -# Copyright:: Copyright (c) 2018-2019 Yegor Bugayenko +# Copyright:: Copyright (c) 2018-2020 Yegor Bugayenko # License:: MIT class Rumble::CLI # Make an instance. def initialize(opts) @opts = opts @@ -110,9 +112,18 @@ body text end html_part do content_type 'text/html; charset=UTF-8' body html + end + end + if @opts[:attach] + Dir.mktmpdir do |dir| + `#{@opts[:attach]} "#{email}" "#{name}" "#{dir}"` + raise 'Failed to exec' unless $CHILD_STATUS.success? + Dir[File.join(dir, '*')].each do |f| + mail.add_file(filename: File.basename(f), content: IO.read(f)) + end end end mail.deliver! unless @opts[:dry] total += 1 puts "#{Rainbow('done').green} ##{total}"