command_line_email 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,55 +11,71 @@ Mail.defaults do
11
11
  delivery_method :smtp, user_config.mail_options
12
12
  end
13
13
 
14
- mail_attrs = {to: []}
14
+ class CleOptparse
15
15
 
16
- option_parser = OptionParser.new do |opts|
16
+ def self.parse(args, user_config)
17
17
 
18
- opts.on("-t TO","--to TO") do |to|
19
- mail_attrs[:to] = to_string_to_mailing_list(user_config, to, mail_attrs[:to])
20
- end
18
+ mail_attrs = {to: []}
21
19
 
22
- opts.on("-f FROM","--from FROM") do |from|
23
- mail_attrs[:from] = from
24
- end
20
+ option_parser = OptionParser.new do |opts|
25
21
 
26
- opts.on("-b BODY","--body BODY") do |body|
27
- mail_attrs[:body] ||= ""
28
- mail_attrs[:body] << body + "\n"
29
- end
22
+ opts.on("-t TO","--to TO") do |to|
23
+ mail_attrs[:to] = to_string_to_mailing_list(user_config, to, mail_attrs[:to])
24
+ end
30
25
 
31
- opts.on("-s SUBJECT","--subject SUBJECT") do |subject|
32
- mail_attrs[:subject] = subject
33
- end
26
+ opts.on("-f FROM","--from FROM") do |from|
27
+ mail_attrs[:from] = from
28
+ end
29
+
30
+ opts.on("-b BODY","--body BODY") do |body|
31
+ mail_attrs[:body] ||= ""
32
+ mail_attrs[:body] << body + "\n"
33
+ end
34
+
35
+ opts.on("-s SUBJECT","--subject SUBJECT") do |subject|
36
+ mail_attrs[:subject] = subject
37
+ end
38
+
39
+ opts.on("-c CC","--cc CC") do |cc|
40
+ if user_config.mailing_lists.has_key? cc.to_sym
41
+ mail_attrs[:cc] = user_config.mailing_lists[cc.to_sym]
42
+ else
43
+ mail_attrs[:cc] = cc
44
+ end
45
+ end
46
+
47
+ opts.on("-f FILE","--add-file FILE") do |file|
48
+ mail_attrs[:files] ||= []
49
+ mail_attrs[:files] << file
50
+ end
51
+
52
+ opts.on("-d DIRECTORY","--directory DIRECTORY") do |directory|
53
+ mail_attrs[:directory] = directory
54
+ end
34
55
 
35
- opts.on("-c CC","--cc CC") do |cc|
36
- if user_config.mailing_lists.has_key? cc.to_sym
37
- mail_attrs[:cc] = user_config.mailing_lists[cc.to_sym]
38
- else
39
- mail_attrs[:cc] = cc
40
56
  end
41
- end
42
57
 
43
- opts.on("-f FILE","--add-file FILE") do |file|
44
- mail_attrs[:files] ||= []
45
- mail_attrs[:files] << file
46
- end
58
+ option_parser.parse!(args)
47
59
 
48
- opts.on("-d DIRECTORY","--directory DIRECTORY") do |directory|
49
- mail_attrs[:directory] = directory
60
+ mail_attrs
61
+
62
+ end # parse()
63
+
64
+ def self.to_string_to_mailing_list(user_config, to, list=[])
65
+ # takes optional list in case you want to add to an existing list
66
+ if user_config.mailing_lists.has_key? to.to_sym
67
+ Array(user_config.mailing_lists[to.to_sym]).each { |address| list << address }
68
+ else
69
+ list << to
70
+ end
71
+ list
50
72
  end
51
73
 
52
- end
74
+ end # class CleOptparse
53
75
 
54
- def to_string_to_mailing_list(user_config, to, list=[])
55
- # takes optional list in case you want to add to an existing list
56
- if user_config.mailing_lists.has_key? to.to_sym
57
- Array(user_config.mailing_lists[to.to_sym]).each { |address| list << address }
58
- else
59
- list << to
60
- end
61
- list
62
- end
76
+ mail_attrs = CleOptparse.parse(ARGV, user_config)
77
+
78
+ puts mail_attrs
63
79
 
64
80
  def grab_text_from_filename_if_file_exists(filename_or_text)
65
81
  if File.exists?(filename_or_text)
@@ -69,10 +85,6 @@ def grab_text_from_filename_if_file_exists(filename_or_text)
69
85
  end
70
86
  end
71
87
 
72
- option_parser.parse!
73
-
74
- puts mail_attrs
75
-
76
88
  mail = Mail.new do
77
89
  from mail_attrs[:from] || user_config.defaults[:from]
78
90
  to mail_attrs[:to] || user_config.defaults[:to]
@@ -1,5 +1,5 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  module CommandLineEmail
4
- VERSION = "0.0.2"
4
+ VERSION = "0.0.3"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: command_line_email
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: