sugoi_aliases_updator 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.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/exe/sugoi_aliases_updator +10 -42
- data/lib/sugoi_aliases_updator.rb +1 -0
- data/lib/sugoi_aliases_updator/aliases_parser.rb +2 -7
- data/lib/sugoi_aliases_updator/cli.rb +63 -0
- data/lib/sugoi_aliases_updator/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a8fd7f2e2371f690b1262b089b4677ef67a3332
|
4
|
+
data.tar.gz: 94b92664db4db779b58b09a788948b71bb0e8533
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 576863837762a3d56d7e7188c659c1b89f8422df17a0b652b6cd4aecf7d189f571ac302d49a1c00d36894864c6691ad75ec674608521853b39dfe73c392065e8
|
7
|
+
data.tar.gz: f324fbae5f5b02433f80466955a77c9e50a2aa404e5a3283518ff8027fd05701f4a395c54731c5f931714620e25e71cc4a8c5bf46f5be5cf91c16e7edce8adf9
|
data/README.md
CHANGED
@@ -12,7 +12,7 @@ gem 'sugoi_aliases_updator'
|
|
12
12
|
'ruby' >= '2.1'
|
13
13
|
|
14
14
|
## Usage
|
15
|
-
add, rm, listのみ。
|
15
|
+
add, rm(del), list(show)のみ。
|
16
16
|
```
|
17
17
|
$ cat /etc/aliases
|
18
18
|
www: root, n905i.1214@gmail.com
|
@@ -28,7 +28,7 @@ postfix: root, n905i.1214@gmail.com
|
|
28
28
|
```
|
29
29
|
|
30
30
|
```
|
31
|
-
$ sugoi_aliases_updator /etc/aliases rm n905i.1214@gmail.com
|
31
|
+
$ sugoi_aliases_updator /etc/aliases rm n905i.1214@gmail.com FROM=www,postfix
|
32
32
|
www: root
|
33
33
|
ftp-bugs: root
|
34
34
|
postfix: root
|
data/exe/sugoi_aliases_updator
CHANGED
@@ -1,50 +1,18 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
filepath = ARGV[0] || ''
|
6
|
-
command = ARGV[1]
|
7
|
-
target_email = ARGV[2]
|
8
|
-
direction_labels = ARGV[3]
|
9
|
-
|
10
|
-
if $*.first == '--version'
|
11
|
-
require "sugoi_aliases_updator/version"
|
12
|
-
puts SugoiAliasesUpdator::VERSION
|
13
|
-
exit 0
|
14
|
-
end
|
15
|
-
|
16
|
-
unless File.exists?(filepath)
|
17
|
-
puts "file is not found "
|
18
|
-
exit 1
|
19
|
-
end
|
20
|
-
|
21
|
-
unless COMMANDS.include?(command)
|
22
|
-
puts "input (#{COMMANDS.join("|")})"
|
23
|
-
exit 1
|
24
|
-
end
|
25
|
-
|
26
|
-
unless /\w*@.*/ =~ target_email
|
27
|
-
puts "input email"
|
28
|
-
exit 1
|
29
|
-
end
|
3
|
+
require "sugoi_aliases_updator"
|
30
4
|
|
31
|
-
|
32
|
-
|
33
|
-
puts "Usage: #{need[command]}=label1,label2"
|
34
|
-
exit 1
|
35
|
-
end
|
5
|
+
cli = SugoiAliasesUpdator::Cli.new(ARGV)
|
6
|
+
cli.check_input
|
36
7
|
|
37
|
-
require "sugoi_aliases_updator"
|
38
8
|
include SugoiAliasesUpdator
|
39
|
-
aliases_parser = AliasesParser.new(filepath)
|
9
|
+
aliases_parser = AliasesParser.new(cli.filepath)
|
40
10
|
|
41
|
-
case command
|
11
|
+
case cli.command
|
42
12
|
when 'add'
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
puts aliases_parser.
|
48
|
-
when 'list'
|
49
|
-
puts aliases_parser.list(target_email)
|
13
|
+
puts aliases_parser.add(cli.target_email, cli.direction_labels)
|
14
|
+
when 'rm', 'del'
|
15
|
+
puts aliases_parser.rm(cli.target_email, cli.direction_labels)
|
16
|
+
when 'list', 'show'
|
17
|
+
puts aliases_parser.list(cli.target_email)
|
50
18
|
end
|
@@ -3,17 +3,12 @@ module SugoiAliasesUpdator
|
|
3
3
|
|
4
4
|
attr_accessor :changed_labels
|
5
5
|
|
6
|
-
def self.parse_direction_labels(string)
|
7
|
-
raise("Oops '#{string}'") unless /(TO|FROM)=(.*)$/ =~ string
|
8
|
-
$2.split(/,\s?/)
|
9
|
-
end
|
10
|
-
|
11
6
|
def initialize(filepath)
|
12
7
|
@native_lines = File.readlines(filepath)
|
13
8
|
@changed_labels = []
|
14
9
|
end
|
15
10
|
|
16
|
-
def add(target_email, to
|
11
|
+
def add(target_email, to)
|
17
12
|
check_labels!(to)
|
18
13
|
to.each do |x|
|
19
14
|
unless label_mails_hash[x].include?(target_email)
|
@@ -24,7 +19,7 @@ module SugoiAliasesUpdator
|
|
24
19
|
render!
|
25
20
|
end
|
26
21
|
|
27
|
-
def rm(target_email, from
|
22
|
+
def rm(target_email, from)
|
28
23
|
if ['ALL'] == from
|
29
24
|
label_mails_hash.each do |label, emails|
|
30
25
|
if emails.include?(target_email)
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module SugoiAliasesUpdator
|
2
|
+
class Cli
|
3
|
+
attr_reader :filepath, :target_email, :command
|
4
|
+
|
5
|
+
COMMANDS = %w(add rm del list show)
|
6
|
+
|
7
|
+
def initialize(args)
|
8
|
+
@filepath = args[0] || ''
|
9
|
+
@command = args[1]
|
10
|
+
@target_email = args[2]
|
11
|
+
@direction_labels = args[3]
|
12
|
+
end
|
13
|
+
|
14
|
+
def check_input
|
15
|
+
display_version
|
16
|
+
check_filepath
|
17
|
+
check_command
|
18
|
+
check_terget_email
|
19
|
+
check_direction
|
20
|
+
end
|
21
|
+
|
22
|
+
def direction_labels
|
23
|
+
raise("Oops '#{@direction_labels}'") unless /(TO|FROM)=(.*)$/ =~ @direction_labels
|
24
|
+
$2.split(/,\s?/)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def display_version
|
30
|
+
return unless @filepath == '--version'
|
31
|
+
require "sugoi_aliases_updator/version"
|
32
|
+
puts SugoiAliasesUpdator::VERSION
|
33
|
+
exit 0
|
34
|
+
end
|
35
|
+
|
36
|
+
def check_filepath
|
37
|
+
return if File.exists?(@filepath)
|
38
|
+
puts "file is not found "
|
39
|
+
exit 1
|
40
|
+
end
|
41
|
+
|
42
|
+
def check_command
|
43
|
+
return if COMMANDS.include?(@command)
|
44
|
+
puts "input (#{COMMANDS.join("|")})"
|
45
|
+
exit 1
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
def check_terget_email
|
50
|
+
return if /\w*@.*/ =~ @target_email
|
51
|
+
puts "input email"
|
52
|
+
exit 1
|
53
|
+
end
|
54
|
+
|
55
|
+
def check_direction
|
56
|
+
if %w(add rm).include?(@command) && @direction_labels.nil?
|
57
|
+
need = { 'add' => 'TO', 'rm' => 'FROM' }
|
58
|
+
puts "Usage: #{need[@command]}=label1,label2"
|
59
|
+
exit 1
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sugoi_aliases_updator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jiikko
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -84,6 +84,7 @@ files:
|
|
84
84
|
- exe/sugoi_aliases_updator
|
85
85
|
- lib/sugoi_aliases_updator.rb
|
86
86
|
- lib/sugoi_aliases_updator/aliases_parser.rb
|
87
|
+
- lib/sugoi_aliases_updator/cli.rb
|
87
88
|
- lib/sugoi_aliases_updator/line_parser.rb
|
88
89
|
- lib/sugoi_aliases_updator/version.rb
|
89
90
|
- sugoi_aliases_updator.gemspec
|
@@ -107,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
108
|
version: '0'
|
108
109
|
requirements: []
|
109
110
|
rubyforge_project:
|
110
|
-
rubygems_version: 2.
|
111
|
+
rubygems_version: 2.2.0
|
111
112
|
signing_key:
|
112
113
|
specification_version: 4
|
113
114
|
summary: "/etc/aliases uppdator."
|