exportr 0.0.3 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1 -1
- data/bin/exportr +2 -5
- data/exportr.gemspec +3 -2
- data/lib/exportr/command.rb +76 -0
- data/lib/exportr/config.rb +19 -0
- data/lib/exportr/error_messages.rb +15 -0
- data/lib/exportr/helpers.rb +16 -0
- data/lib/exportr/version.rb +1 -1
- data/lib/generators/exportr/exportr_generator.rb +1 -0
- data/lib/generators/exportr/templates/exportr.yml +1 -2
- metadata +5 -1
data/README
CHANGED
data/bin/exportr
CHANGED
@@ -1,8 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
|
-
$LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
|
3
|
+
require 'exportr/command'
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
puts "exportr rules"
|
5
|
+
Exportr::Command.run *ARGV
|
data/exportr.gemspec
CHANGED
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
21
|
# specify any dependencies here; for example:
|
22
|
-
#
|
23
|
-
# s.add_runtime_dependency "
|
22
|
+
#s.add_development_dependency "optparse"
|
23
|
+
# s.add_runtime_dependency "optparse"
|
24
|
+
|
24
25
|
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'exportr/config'
|
3
|
+
require 'exportr/error_messages'
|
4
|
+
require 'exportr/helpers'
|
5
|
+
|
6
|
+
module Exportr
|
7
|
+
|
8
|
+
module Command
|
9
|
+
|
10
|
+
extend Exportr::Config
|
11
|
+
extend Exportr::ErrorMessages
|
12
|
+
extend Exportr::Helpers
|
13
|
+
|
14
|
+
global_option :add, '-a', '--add VAR', 'Add environment variable'
|
15
|
+
global_option :remove, '-r', '--remove VAR', 'Remove environment variable'
|
16
|
+
|
17
|
+
def self.run *argv
|
18
|
+
error not_root unless at_root?
|
19
|
+
parser.parse! argv
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.add val
|
23
|
+
vars = load_config
|
24
|
+
vars.merge! val
|
25
|
+
write_config vars
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.remove val
|
29
|
+
vars = load_config
|
30
|
+
write_config vars.reject { |k,v| k == val.to_a[0][0] }
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.parser
|
34
|
+
OptionParser.new do |parser|
|
35
|
+
global_options.each do |opt|
|
36
|
+
parser.on *opt[:args] do |val|
|
37
|
+
send opt[:name], hashify(val)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.read_config
|
44
|
+
error no_config_file unless File.exists?(config_file)
|
45
|
+
File.read config_file
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.write_config vars
|
49
|
+
cm = comments
|
50
|
+
File.open config_file, 'w+' do |f|
|
51
|
+
f.write cm << "\n" << dump_config(vars)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.load_config
|
56
|
+
YAML.load(read_config) || Hash.new
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.dump_config vars
|
60
|
+
YAML.dump(vars)
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.comments
|
64
|
+
read_config.match(/(^\#.*\n)+/).to_s
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.hashify str
|
68
|
+
arr = str.split '='
|
69
|
+
hash = Hash.new
|
70
|
+
hash[arr[0]] = arr[1]
|
71
|
+
hash
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Exportr
|
2
|
+
|
3
|
+
module Config
|
4
|
+
|
5
|
+
def global_options
|
6
|
+
@global_options ||= []
|
7
|
+
end
|
8
|
+
|
9
|
+
def global_option name, *args
|
10
|
+
global_options << { :name => name, :args => args }
|
11
|
+
end
|
12
|
+
|
13
|
+
def config_file
|
14
|
+
"config/exportr.yml"
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
data/lib/exportr/version.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# This file is loaded at app initialization to set app specific environment variables
|
2
2
|
# set environment variables in the format [KEY]: [VALUE], each separated by a newline
|
3
|
-
|
4
|
-
# Examples:
|
3
|
+
#
|
5
4
|
# FACEBOOK_APP_KEY: '234443366312034'
|
6
5
|
# S3_BUCKET: 'myapp-production'
|
7
6
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: exportr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -27,6 +27,10 @@ files:
|
|
27
27
|
- bin/exportr
|
28
28
|
- exportr.gemspec
|
29
29
|
- lib/exportr.rb
|
30
|
+
- lib/exportr/command.rb
|
31
|
+
- lib/exportr/config.rb
|
32
|
+
- lib/exportr/error_messages.rb
|
33
|
+
- lib/exportr/helpers.rb
|
30
34
|
- lib/exportr/version.rb
|
31
35
|
- lib/generators/exportr/exportr_generator.rb
|
32
36
|
- lib/generators/exportr/templates/exportr.rb
|