envfile 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README +43 -0
- data/bin/envfile +42 -0
- data/lib/envfile.rb +132 -0
- metadata +189 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 05c6eb2d30fff750c54ba4323da2130aab802c08
|
4
|
+
data.tar.gz: 275b0a8d58f3c57898148aeaad68c4de77961385
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2b35626578dbaff91a20e90f9e725588454cee89fe1b34d132d7f4ddaf08f0693f39d6ffb8544cf6f3fa1034c898d6e3a9f072a050fd7baf9a38d58b46d70dc2
|
7
|
+
data.tar.gz: e5cfa3074313b95059842acd6f291a72cea00e2c770959038b2695b7a5a426d75f733756e41bfcb088f80a1da66e66095b7a8f2a14997ddb07ebb81fb9ef328e
|
data/README
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
ENVFILE(1) BSD General Commands Manual ENVFILE(1)
|
2
|
+
|
3
|
+
NAME
|
4
|
+
envfile - execute a command under a crafted environment
|
5
|
+
|
6
|
+
SYNOPSIS
|
7
|
+
envfile foo.env -- program [argv...]
|
8
|
+
|
9
|
+
DESCRIPTION
|
10
|
+
The envfile(1) is a program to run another program; much
|
11
|
+
like sudo(1) or chroot(1). The difference is that this
|
12
|
+
program is designed to modify environment variables before
|
13
|
+
that.
|
14
|
+
|
15
|
+
FILES
|
16
|
+
The `envfile(1)` program takes an env file as its first
|
17
|
+
argument. They can either be one of
|
18
|
+
|
19
|
+
* Perl program when their suffixes are '.pl' or '.perl';
|
20
|
+
* JSON file when their suffixes are '.js' or '.json';
|
21
|
+
* YAML file when their suffixes are '.yml' or '.yaml';
|
22
|
+
* Otherwise envfile formatted, where KEY=VALUE is written
|
23
|
+
each line.
|
24
|
+
|
25
|
+
EXAMPLES
|
26
|
+
$ cat > foo.env
|
27
|
+
FOO=foo
|
28
|
+
BAR=bar
|
29
|
+
^D
|
30
|
+
$ envfile foo.env ruby -e 'puts ENV["FOO"], ENV["BAR"]'
|
31
|
+
foo
|
32
|
+
bar
|
33
|
+
|
34
|
+
AUTHOR
|
35
|
+
This is a Ruby translation of p5-App-envfile by Urabe,
|
36
|
+
Shyouhei <shyouhei@ruby-lang.org>. Original Perl version
|
37
|
+
was by xaicron <xaicron@cpan.org>.
|
38
|
+
|
39
|
+
BUGS
|
40
|
+
You need a working Perl interpreter to understand Perl
|
41
|
+
program.
|
42
|
+
|
43
|
+
ENVFILE(1) BSD General Commands Manual ENVFILE(1)
|
data/bin/envfile
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
#! /your/favourite/path/for/ruby
|
2
|
+
# -*- coding: utf-8; -*-
|
3
|
+
#
|
4
|
+
# Copyright(c) 2013 URABE, Shyouhei.
|
5
|
+
#
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
# of this code, to deal in the code without restriction, including without
|
8
|
+
# limitation the rights to use, copy, modify, merge, publish, distribute,
|
9
|
+
# sublicense, and/or sell copies of the code, and to permit persons to whom the
|
10
|
+
# code is furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the code.
|
14
|
+
#
|
15
|
+
# THE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHOR OR COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE CODE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
# CODE.
|
22
|
+
|
23
|
+
require 'envfile'
|
24
|
+
|
25
|
+
abort "usage: #$0 FILE -- CMD [ARGV...]" unless efile = ARGV.shift
|
26
|
+
ARGV.shift if ARGV[0] == '--' # ignore separator
|
27
|
+
abort "usage: #$0 FILE -- CMD [ARGV...]" if ARGV.empty?
|
28
|
+
|
29
|
+
# Here we go
|
30
|
+
Envfile.run_with_envfile(efile, *ARGV)
|
31
|
+
|
32
|
+
#
|
33
|
+
# Local Variables:
|
34
|
+
# mode: ruby
|
35
|
+
# coding: utf-8
|
36
|
+
# indent-tabs-mode: nil
|
37
|
+
# tab-width: 3
|
38
|
+
# ruby-indent-level: 3
|
39
|
+
# fill-column: 79
|
40
|
+
# default-justification: full
|
41
|
+
# End:
|
42
|
+
# vi:ts=3:sw=3:
|
data/lib/envfile.rb
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
#! /your/favourite/path/for/ruby
|
2
|
+
# -*- coding: utf-8; -*-
|
3
|
+
#
|
4
|
+
# Copyright(c) 2013 URABE, Shyouhei.
|
5
|
+
#
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
# of this code, to deal in the code without restriction, including without
|
8
|
+
# limitation the rights to use, copy, modify, merge, publish, distribute,
|
9
|
+
# sublicense, and/or sell copies of the code, and to permit persons to whom the
|
10
|
+
# code is furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the code.
|
14
|
+
#
|
15
|
+
# THE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHOR OR COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE CODE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
# CODE.
|
22
|
+
|
23
|
+
require 'json'
|
24
|
+
require 'psych'
|
25
|
+
require 'pathname'
|
26
|
+
|
27
|
+
# Envfile understands various input file formats and executes commands
|
28
|
+
# according to that.
|
29
|
+
#
|
30
|
+
# It should be noted that Envfile is (unlike the ENV object itself) a kind of
|
31
|
+
# Hash. So if you want to modify some environment variables, feel free to do
|
32
|
+
# so as you normally do with Hashes. It is of course up to you to properly set
|
33
|
+
# them up.
|
34
|
+
class Envfile < Hash
|
35
|
+
|
36
|
+
# Utility method to setup, fire, then forget.
|
37
|
+
#
|
38
|
+
# @param [String] envfile an envfile path
|
39
|
+
# @param [String] cmd program file path
|
40
|
+
# @param [String] argv passed to cmd
|
41
|
+
#
|
42
|
+
# @see Envfile#exec!
|
43
|
+
def self.run_with_envfile envfile, cmd, *argv
|
44
|
+
new.parse(envfile).exec!(cmd, argv)
|
45
|
+
end
|
46
|
+
|
47
|
+
# Load up the contents of the given file.
|
48
|
+
# @param [String] envfile path to a file
|
49
|
+
#
|
50
|
+
# @note When called multiple times with different envfile per instance, and
|
51
|
+
# if any of the env key collides, the result is undefined. I would
|
52
|
+
# like to advise you no to do such thing.
|
53
|
+
def parse envfile
|
54
|
+
path = Pathname.new envfile
|
55
|
+
update case path.extname
|
56
|
+
when '.pl', '.perl' then parse_perl path
|
57
|
+
when '.js', '.json' then parse_json path
|
58
|
+
when '.yml', '.yaml' then parse_yaml path
|
59
|
+
else parse_xaicron path
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# Executes the given cmd under self's setup.
|
64
|
+
# @param [String] cmd program file path
|
65
|
+
# @param [String] argv passed to cmd
|
66
|
+
#
|
67
|
+
# @note This method does not always return. But when it does it always
|
68
|
+
# results into an exception.
|
69
|
+
#
|
70
|
+
# @raise [Errno::ENOENT] envfile does not exist
|
71
|
+
# @raise [Errno::ENOEXEC] cmd not runnable
|
72
|
+
# @raise [Errno::EACCESS] permission denied to exec
|
73
|
+
# @raise [Errno::ELOOP] symlink is too deep
|
74
|
+
# @raise [Errno::ENAMETOOLONG] file path too long
|
75
|
+
def exec! cmd, argv
|
76
|
+
exec self, [cmd, cmd], *argv, close_others: true
|
77
|
+
end
|
78
|
+
|
79
|
+
#
|
80
|
+
private
|
81
|
+
|
82
|
+
def parse_json path
|
83
|
+
path.open do |f|
|
84
|
+
return JSON.load f
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def parse_yaml path
|
89
|
+
path.open do |f|
|
90
|
+
return Psych.load f
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def parse_perl path
|
95
|
+
IO.popen 'perl', 'r+' do |io|
|
96
|
+
io.puts <<-"end"
|
97
|
+
use App::envfile;
|
98
|
+
use JSON::XS;
|
99
|
+
my $json = JSON::XS->new->utf8->allow_nonref;
|
100
|
+
my $envf = App::envfile->new->parse_envfile('#{path}');
|
101
|
+
print $json->encode($envf);
|
102
|
+
exit;
|
103
|
+
end
|
104
|
+
io.close_write
|
105
|
+
return JSON.load io
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def parse_xaicron path
|
110
|
+
path.open do |f|
|
111
|
+
return f.each_line.reject do |i|
|
112
|
+
/^\s*#/ =~ i
|
113
|
+
end.map do |i|
|
114
|
+
i.chomp.split %r/=/, 2
|
115
|
+
end.each_with_object Hash.new do |(k, v), h|
|
116
|
+
h[k] = v
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
#
|
123
|
+
# Local Variables:
|
124
|
+
# mode: ruby
|
125
|
+
# coding: utf-8
|
126
|
+
# indent-tabs-mode: nil
|
127
|
+
# tab-width: 3
|
128
|
+
# ruby-indent-level: 3
|
129
|
+
# fill-column: 79
|
130
|
+
# default-justification: full
|
131
|
+
# End:
|
132
|
+
# vi:ts=3:sw=3:
|
metadata
ADDED
@@ -0,0 +1,189 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: envfile
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Urabe, Shyouhei
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-05-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: yard
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.8'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rdoc
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.13'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.13'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: bundler
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: pit
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: json
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: psych
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :runtime
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - '>='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
description: "The `envfile(1)` program is a program to run another program; much
|
154
|
+
like\n\t\t`sudo(1)` or `chroot(1)`. The difference is that this program
|
155
|
+
\ is\n\t\tdesigned to modify environment variables before that."
|
156
|
+
email:
|
157
|
+
executables:
|
158
|
+
- envfile
|
159
|
+
extensions: []
|
160
|
+
extra_rdoc_files: []
|
161
|
+
files:
|
162
|
+
- lib/envfile.rb
|
163
|
+
- README
|
164
|
+
- bin/envfile
|
165
|
+
homepage: https://github.com/shyouhei/envfile
|
166
|
+
licenses:
|
167
|
+
- MIT
|
168
|
+
metadata: {}
|
169
|
+
post_install_message:
|
170
|
+
rdoc_options: []
|
171
|
+
require_paths:
|
172
|
+
- lib
|
173
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
174
|
+
requirements:
|
175
|
+
- - '>='
|
176
|
+
- !ruby/object:Gem::Version
|
177
|
+
version: 1.9.3
|
178
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
179
|
+
requirements:
|
180
|
+
- - '>='
|
181
|
+
- !ruby/object:Gem::Version
|
182
|
+
version: '0'
|
183
|
+
requirements: []
|
184
|
+
rubyforge_project:
|
185
|
+
rubygems_version: 2.0.0
|
186
|
+
signing_key:
|
187
|
+
specification_version: 4
|
188
|
+
summary: envfile(1), to execute another command under a modified environment
|
189
|
+
test_files: []
|