ironment 0.0.1
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 +7 -0
- data/.travis.yml +13 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +20 -0
- data/LICENSE +20 -0
- data/README.md +28 -0
- data/Rakefile +7 -0
- data/bin/iron +26 -0
- data/ironment.gemspec +40 -0
- data/lib/ironment/executor.rb +7 -0
- data/lib/ironment/finder.rb +30 -0
- data/lib/ironment/populator.rb +16 -0
- data/lib/ironment/version.rb +3 -0
- data/lib/ironment.rb +34 -0
- data/test/finder_test.rb +48 -0
- data/test/ironment_test.rb +25 -0
- data/test/populator_test.rb +47 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9bdd77dc405bac4474f7721fd16c102c3524220b
|
4
|
+
data.tar.gz: 8482bb744aafa577e15c4efdefb642fde2089cb5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9f8c79750ead0345cd59660c84a4445662242cf2440f12a48ce059d70300ca97850a1763b4655a2d03e7b6a6140b01dbc7e8728a09ce82d42b2dfe961b0ae302
|
7
|
+
data.tar.gz: b39bd04abc6afcbe48e326e2bc4b0ab447828a0c325e9277c37254065232a61c5fa4b19a9fb56ea163650c871f5836d16a4b4ca8f91bc7144e1418308b27ec37
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2013 Jonas Amundsen
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
Ironment
|
2
|
+
========
|
3
|
+
|
4
|
+
[](https://travis-ci.org/badeball/ironment)
|
5
|
+
|
6
|
+
Ironment is a simple command line utility for populating the environment of a
|
7
|
+
command by reading particular environment files and then exec-ing. Such
|
8
|
+
environment files may look like the following.
|
9
|
+
|
10
|
+
```
|
11
|
+
# ./.envrc
|
12
|
+
FOO=bar
|
13
|
+
```
|
14
|
+
|
15
|
+
Any command wrapped with `iron` will see the environment variables.
|
16
|
+
|
17
|
+
```
|
18
|
+
$ iron env
|
19
|
+
FOO=bar
|
20
|
+
```
|
21
|
+
|
22
|
+
## Changelog
|
23
|
+
|
24
|
+
### 0.0.1
|
25
|
+
|
26
|
+
* Initial version. Contains basic support for wrapping commands and populating
|
27
|
+
the environment by recursively reading the directory structure upwards and
|
28
|
+
looking for .envrc files.
|
data/Rakefile
ADDED
data/bin/iron
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "optparse"
|
4
|
+
require "ironment"
|
5
|
+
|
6
|
+
opts = OptionParser.new do |opts|
|
7
|
+
opts.banner = "Usage: ironment [options] COMMAND"
|
8
|
+
|
9
|
+
opts.on_tail("-h", "--help", "show this message") do
|
10
|
+
puts opts
|
11
|
+
exit
|
12
|
+
end
|
13
|
+
|
14
|
+
opts.on_tail("-v", "--version", "print the version number of ironment") do
|
15
|
+
puts "ironment #{Ironment::VERSION}"
|
16
|
+
exit
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
opts.parse!
|
21
|
+
|
22
|
+
if ARGV.empty?
|
23
|
+
raise ArgumentError, "missing command"
|
24
|
+
end
|
25
|
+
|
26
|
+
Ironment.new.exec_with_environment *ARGV
|
data/ironment.gemspec
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "lib", "ironment", "version")
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "ironment"
|
5
|
+
s.version = Ironment::VERSION
|
6
|
+
s.license = "MIT"
|
7
|
+
s.date = "2015-05-04"
|
8
|
+
|
9
|
+
s.summary = "Automatic environment variable container."
|
10
|
+
s.description = "Ironment populates environment variables with runcoms and executes commands."
|
11
|
+
|
12
|
+
s.authors = ["Jonas Amundsen"]
|
13
|
+
s.email = ["jonasba+gem@gmail.com"]
|
14
|
+
s.homepage = "https://github.com/badeball/ironment"
|
15
|
+
|
16
|
+
s.executables = "iron"
|
17
|
+
|
18
|
+
s.files = %w[
|
19
|
+
.travis.yml
|
20
|
+
Gemfile
|
21
|
+
Gemfile.lock
|
22
|
+
LICENSE
|
23
|
+
README.md
|
24
|
+
Rakefile
|
25
|
+
bin/iron
|
26
|
+
ironment.gemspec
|
27
|
+
lib/ironment.rb
|
28
|
+
lib/ironment/executor.rb
|
29
|
+
lib/ironment/finder.rb
|
30
|
+
lib/ironment/populator.rb
|
31
|
+
lib/ironment/version.rb
|
32
|
+
test/finder_test.rb
|
33
|
+
test/ironment_test.rb
|
34
|
+
test/populator_test.rb
|
35
|
+
]
|
36
|
+
|
37
|
+
s.add_development_dependency("fakefs")
|
38
|
+
s.add_development_dependency("minitest")
|
39
|
+
s.add_development_dependency("rake")
|
40
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "pathname"
|
2
|
+
|
3
|
+
class Ironment
|
4
|
+
class Finder
|
5
|
+
def initialize
|
6
|
+
@pwd = Pathname.pwd
|
7
|
+
end
|
8
|
+
|
9
|
+
def find
|
10
|
+
Enumerator.new do |y|
|
11
|
+
until @pwd.root?
|
12
|
+
y << cdrc if has_cdrc?
|
13
|
+
@pwd = @pwd.parent
|
14
|
+
end
|
15
|
+
|
16
|
+
y << cdrc if has_cdrc?
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def has_cdrc?
|
23
|
+
File.exist? cdrc
|
24
|
+
end
|
25
|
+
|
26
|
+
def cdrc
|
27
|
+
File.join @pwd, Ironment.runcom
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class Ironment
|
2
|
+
class Populator
|
3
|
+
def initialize(options = {})
|
4
|
+
@env = options[:env] || ENV
|
5
|
+
end
|
6
|
+
|
7
|
+
def populate_with(name)
|
8
|
+
File.readlines(name).each do |line|
|
9
|
+
unless /^\s*#/ =~ line
|
10
|
+
key, value = line.strip.split "="
|
11
|
+
@env[key] = value
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/ironment.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require "ironment/finder"
|
2
|
+
require "ironment/populator"
|
3
|
+
require "ironment/executor"
|
4
|
+
|
5
|
+
class Ironment
|
6
|
+
class << self
|
7
|
+
attr_writer :runcom
|
8
|
+
|
9
|
+
def runcom
|
10
|
+
@runcom || default_runcom
|
11
|
+
end
|
12
|
+
|
13
|
+
def default_runcom
|
14
|
+
".envrc"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(options = {})
|
19
|
+
@finder = options[:finder] || Finder.new
|
20
|
+
@populator = options[:populator] || Populator.new
|
21
|
+
@executor = options[:executor] || Executor.new
|
22
|
+
end
|
23
|
+
|
24
|
+
def exec_with_environment(command, *args)
|
25
|
+
load_environment
|
26
|
+
@executor.exec command, *args
|
27
|
+
end
|
28
|
+
|
29
|
+
def load_environment
|
30
|
+
@finder.find.each do |runcom|
|
31
|
+
@populator.populate_with runcom
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/test/finder_test.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require "minitest/autorun"
|
2
|
+
require "fakefs/safe"
|
3
|
+
require "ironment"
|
4
|
+
|
5
|
+
module FakeFS
|
6
|
+
class Pathname
|
7
|
+
def root?
|
8
|
+
!!(chop_basename(@path).nil? && /#{SEPARATOR_PAT}/o =~ @path)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe Ironment::Finder do
|
14
|
+
before :each do
|
15
|
+
FakeFS.activate!
|
16
|
+
Dir.mkdir "/foo"
|
17
|
+
Dir.mkdir "/foo/bar"
|
18
|
+
end
|
19
|
+
|
20
|
+
after :each do
|
21
|
+
FakeFS::FileSystem.clear
|
22
|
+
FakeFS.deactivate!
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should return the runcom in the current directory" do
|
26
|
+
FileUtils.touch "/foo/bar/.envrc"
|
27
|
+
|
28
|
+
Dir.chdir "/foo/bar" do
|
29
|
+
assert_includes Ironment::Finder.new.find, "/foo/bar/.envrc"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should return the runcom somewhere in the upper directory" do
|
34
|
+
FileUtils.touch "/foo/.envrc"
|
35
|
+
|
36
|
+
Dir.chdir "/foo/bar" do
|
37
|
+
assert_includes Ironment::Finder.new.find, "/foo/.envrc"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should return the runcom in the root directory" do
|
42
|
+
FileUtils.touch "/.envrc"
|
43
|
+
|
44
|
+
Dir.chdir "/foo/bar" do
|
45
|
+
assert_includes Ironment::Finder.new.find, "/.envrc"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "minitest/autorun"
|
2
|
+
require "ironment"
|
3
|
+
|
4
|
+
describe Ironment do
|
5
|
+
describe "#exec_with_environment" do
|
6
|
+
it "find all runcoms, populate with their data and exec the command" do
|
7
|
+
finder = Minitest::Mock.new
|
8
|
+
finder.expect :find, ["/foo/.ironment"].to_enum
|
9
|
+
|
10
|
+
populator = Minitest::Mock.new
|
11
|
+
populator.expect :populate_with, true, ["/foo/.ironment"]
|
12
|
+
|
13
|
+
executor = Minitest::Mock.new
|
14
|
+
executor.expect :exec, true, ["some-command"]
|
15
|
+
|
16
|
+
Ironment.new({
|
17
|
+
finder: finder,
|
18
|
+
populator: populator,
|
19
|
+
executor: executor
|
20
|
+
}).exec_with_environment "some-command"
|
21
|
+
|
22
|
+
[finder, populator, executor].each &:verify
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require "minitest/autorun"
|
2
|
+
require "fakefs/safe"
|
3
|
+
require "ironment"
|
4
|
+
|
5
|
+
describe Ironment::Populator do
|
6
|
+
before :each do
|
7
|
+
FakeFS.activate!
|
8
|
+
end
|
9
|
+
|
10
|
+
after :each do
|
11
|
+
FakeFS::FileSystem.clear
|
12
|
+
FakeFS.deactivate!
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should read a file and populate the environment with its content" do
|
16
|
+
File.write("/foo", <<-DAT.gsub(/^\s+/, ""))
|
17
|
+
BAR=1
|
18
|
+
BAZ=2
|
19
|
+
DAT
|
20
|
+
|
21
|
+
env = Minitest::Mock.new
|
22
|
+
env.expect :[]=, "1", ["BAR", "1"]
|
23
|
+
env.expect :[]=, "2", ["BAZ", "2"]
|
24
|
+
|
25
|
+
Ironment::Populator.new(
|
26
|
+
env: env
|
27
|
+
).populate_with "/foo"
|
28
|
+
|
29
|
+
env.verify
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should ignore comment lines" do
|
33
|
+
File.write("/foo", <<-DAT.gsub(/^\s+/, ""))
|
34
|
+
# This is a comment
|
35
|
+
DAT
|
36
|
+
|
37
|
+
env = Minitest::Mock.new
|
38
|
+
|
39
|
+
# Expect no invokations
|
40
|
+
|
41
|
+
Ironment::Populator.new(
|
42
|
+
env: env
|
43
|
+
).populate_with "/foo"
|
44
|
+
|
45
|
+
env.verify
|
46
|
+
end
|
47
|
+
end
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ironment
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jonas Amundsen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: fakefs
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Ironment populates environment variables with runcoms and executes commands.
|
56
|
+
email:
|
57
|
+
- jonasba+gem@gmail.com
|
58
|
+
executables:
|
59
|
+
- iron
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".travis.yml"
|
64
|
+
- Gemfile
|
65
|
+
- Gemfile.lock
|
66
|
+
- LICENSE
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/iron
|
70
|
+
- ironment.gemspec
|
71
|
+
- lib/ironment.rb
|
72
|
+
- lib/ironment/executor.rb
|
73
|
+
- lib/ironment/finder.rb
|
74
|
+
- lib/ironment/populator.rb
|
75
|
+
- lib/ironment/version.rb
|
76
|
+
- test/finder_test.rb
|
77
|
+
- test/ironment_test.rb
|
78
|
+
- test/populator_test.rb
|
79
|
+
homepage: https://github.com/badeball/ironment
|
80
|
+
licenses:
|
81
|
+
- MIT
|
82
|
+
metadata: {}
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 2.4.5
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: Automatic environment variable container.
|
103
|
+
test_files: []
|