ironment 1.0.2 → 1.1.0
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 +6 -0
- data/bin/iron +1 -35
- data/lib/ironment.rb +3 -0
- data/lib/ironment/optparse.rb +81 -0
- data/lib/ironment/optparse/help_texts.rb +83 -0
- data/lib/ironment/version.rb +1 -1
- data/test/optparse_test.rb +141 -0
- data/test/test_helper.rb +2 -2
- metadata +16 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dec374e4c49972f58d40fb7e79634773e2976897
|
4
|
+
data.tar.gz: aab2478fd0f04eb260f0769ff380e377eacce6e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 454ae0ac18f0a36ef243b79301bdac830fde933abcd960a6f7f0fb04e5df2d6948f674ff4d727a3a6b54f29b1d1e9da6fdb8b49c3c1c64a465378f2468e8f068
|
7
|
+
data.tar.gz: 66e7a89d0f77ddea16814dae968b4ddd360102cabd3c18841e66e5bec0cb4b5c5c95a22707ad3aad0e7bb0f3a200b418decc3b718b432e242790a0d71ff103dc
|
data/README.md
CHANGED
@@ -43,6 +43,10 @@ $ yaourt -S ruby-ironment
|
|
43
43
|
|
44
44
|
## Changelog
|
45
45
|
|
46
|
+
### 1.1.0
|
47
|
+
|
48
|
+
* Remove runtime dependency on [commander][commander].
|
49
|
+
|
46
50
|
### 1.0.2
|
47
51
|
|
48
52
|
* Correct a regression of the view feature of the executable.
|
@@ -84,3 +88,5 @@ $ yaourt -S ruby-ironment
|
|
84
88
|
* Initial version. Contains basic support for wrapping commands and populating
|
85
89
|
the environment by recursively reading the directory structure upwards and
|
86
90
|
looking for .envrc files.
|
91
|
+
|
92
|
+
[commander]: https://github.com/commander-rb/commander
|
data/bin/iron
CHANGED
@@ -1,44 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require "commander/import"
|
4
3
|
require "ironment"
|
5
|
-
require "ironment/version"
|
6
4
|
|
7
5
|
Signal.trap("INT") do
|
8
6
|
puts "Aborted"
|
9
7
|
exit 1
|
10
8
|
end
|
11
9
|
|
12
|
-
|
13
|
-
program :version, Ironment::VERSION
|
14
|
-
program :description, "Environment populator & command wrapper utility."
|
15
|
-
|
16
|
-
command :exec do |c|
|
17
|
-
c.syntax = "exec [files..]"
|
18
|
-
c.description = "create a new environment (default)"
|
19
|
-
c.action do |args|
|
20
|
-
Ironment::CL.new.exec_with_environment *args
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
command :trust do |c|
|
25
|
-
c.syntax = "trust [files..]"
|
26
|
-
c.description = "add a file as trusted"
|
27
|
-
c.action do |args|
|
28
|
-
args.each do |file|
|
29
|
-
Ironment::CL.new.trust file
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
command :untrust do |c|
|
35
|
-
c.syntax = "untrust [files..]"
|
36
|
-
c.description = "remove a file as trusted"
|
37
|
-
c.action do |args|
|
38
|
-
args.each do |file|
|
39
|
-
Ironment::CL.new.untrust file
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
default_command :exec
|
10
|
+
exit Ironment::Optparse.new(argv: ARGV).parse || 0
|
data/lib/ironment.rb
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
require "ironment/cl"
|
2
2
|
require "ironment/config"
|
3
3
|
require "ironment/finder"
|
4
|
+
require "ironment/optparse/help_texts"
|
5
|
+
require "ironment/optparse"
|
4
6
|
require "ironment/populator"
|
5
7
|
require "ironment/cl/prompter"
|
6
8
|
require "ironment/executor"
|
7
9
|
require "ironment/runcom"
|
8
10
|
require "ironment/truster"
|
11
|
+
require "ironment/version"
|
9
12
|
|
10
13
|
class Ironment
|
11
14
|
class IronmentError < StandardError; end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
class Ironment
|
2
|
+
class Optparse
|
3
|
+
HELP_OPTIONS = ["-h", "--help"]
|
4
|
+
VERSION_OPTIONS = ["-v", "--version"]
|
5
|
+
|
6
|
+
def initialize(options = {})
|
7
|
+
@argv = options[:argv] || ARGV
|
8
|
+
@stdout = options[:stdout] || $stdout
|
9
|
+
@stderr = options[:stderr] || $stderr
|
10
|
+
@cl = options[:cl] || CL.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def parse
|
14
|
+
if include_version?(@argv)
|
15
|
+
@stdout.puts "Ironment #{VERSION}"
|
16
|
+
return
|
17
|
+
end
|
18
|
+
|
19
|
+
unknown_options = options(@argv) - HELP_OPTIONS - VERSION_OPTIONS
|
20
|
+
|
21
|
+
if !unknown_options.empty?
|
22
|
+
@stderr.puts "Unknown option: #{unknown_options.first}"
|
23
|
+
return 1
|
24
|
+
end
|
25
|
+
|
26
|
+
case @argv.first
|
27
|
+
when "help"
|
28
|
+
case @argv[1]
|
29
|
+
when "exec"
|
30
|
+
@stdout.puts EXEC_HELP_TEXT
|
31
|
+
when "trust"
|
32
|
+
@stdout.puts TRUST_HELP_TEXT
|
33
|
+
when "untrust"
|
34
|
+
@stdout.puts UNTRUST_HELP_TEXT
|
35
|
+
when "help", nil
|
36
|
+
@stdout.puts BASE_HELP_TEXT
|
37
|
+
else
|
38
|
+
@stderr.puts "Unknown command: #{@argv[1]}"
|
39
|
+
return 1
|
40
|
+
end
|
41
|
+
when "trust"
|
42
|
+
return @stdout.puts TRUST_HELP_TEXT if include_help?(@argv)
|
43
|
+
@argv.drop(1).each do |arg|
|
44
|
+
@cl.trust arg
|
45
|
+
end
|
46
|
+
when "untrust"
|
47
|
+
return @stdout.puts UNTRUST_HELP_TEXT if include_help?(@argv)
|
48
|
+
@argv.drop(1).each do |arg|
|
49
|
+
@cl.untrust arg
|
50
|
+
end
|
51
|
+
when "exec"
|
52
|
+
return @stdout.puts EXEC_HELP_TEXT if include_help?(@argv)
|
53
|
+
@cl.exec_with_environment *@argv.drop(1)
|
54
|
+
else
|
55
|
+
return @stdout.puts BASE_HELP_TEXT if include_help?(@argv)
|
56
|
+
return @stdout.puts BASE_HELP_TEXT if @argv.empty?
|
57
|
+
@cl.exec_with_environment *@argv
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def include_help?(argv)
|
64
|
+
!(options(argv) & HELP_OPTIONS).empty?
|
65
|
+
end
|
66
|
+
|
67
|
+
def include_version?(argv)
|
68
|
+
!(options(argv) & VERSION_OPTIONS).empty?
|
69
|
+
end
|
70
|
+
|
71
|
+
def options(argv)
|
72
|
+
if ["help", "exec", "trust", "untrust"].include?(argv.first)
|
73
|
+
argv = argv.drop(1)
|
74
|
+
end
|
75
|
+
|
76
|
+
argv.take_while do |arg|
|
77
|
+
arg.start_with?("-")
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
class Ironment
|
2
|
+
class Optparse
|
3
|
+
class << self
|
4
|
+
private
|
5
|
+
|
6
|
+
def unindent(s)
|
7
|
+
s.gsub(/^#{s.scan(/^[ \t]+(?=\S)/).min}/, '')
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
BASE_HELP_TEXT = unindent(<<-TXT)
|
12
|
+
Environment populator & command wrapper utility.
|
13
|
+
|
14
|
+
\e[1mUSAGE\e[0m
|
15
|
+
|
16
|
+
$ iron COMMAND [OPTIONS]...
|
17
|
+
|
18
|
+
\e[1mCOMMANDS\e[0m
|
19
|
+
|
20
|
+
exec Create a new environment (default)
|
21
|
+
help Display global or [command] help documentation
|
22
|
+
trust Add a file as trusted
|
23
|
+
untrust Remove a file as trusted
|
24
|
+
|
25
|
+
\e[1mGLOBAL OPTIONS\e[0m
|
26
|
+
|
27
|
+
-h, --help
|
28
|
+
Display help documentation
|
29
|
+
|
30
|
+
-v, --version
|
31
|
+
Display version information
|
32
|
+
TXT
|
33
|
+
|
34
|
+
EXEC_HELP_TEXT = unindent(<<-TXT)
|
35
|
+
Create a new environment
|
36
|
+
|
37
|
+
\e[1mUSAGE\e[0m
|
38
|
+
|
39
|
+
$ iron exec COMMAND [ARG]...
|
40
|
+
$ iron COMMAND [ARG]...
|
41
|
+
|
42
|
+
\e[1mGLOBAL OPTIONS\e[0m
|
43
|
+
|
44
|
+
-h, --help
|
45
|
+
Display help documentation
|
46
|
+
|
47
|
+
-v, --version
|
48
|
+
Display version information
|
49
|
+
TXT
|
50
|
+
|
51
|
+
TRUST_HELP_TEXT = unindent(<<-TXT)
|
52
|
+
Add a file / files as trusted
|
53
|
+
|
54
|
+
\e[1mUSAGE\e[0m
|
55
|
+
|
56
|
+
$ iron trust [FILE]...
|
57
|
+
|
58
|
+
\e[1mGLOBAL OPTIONS\e[0m
|
59
|
+
|
60
|
+
-h, --help
|
61
|
+
Display help documentation
|
62
|
+
|
63
|
+
-v, --version
|
64
|
+
Display version information
|
65
|
+
TXT
|
66
|
+
|
67
|
+
UNTRUST_HELP_TEXT = unindent(<<-TXT)
|
68
|
+
Remove a file / files as trusted
|
69
|
+
|
70
|
+
\e[1mUSAGE\e[0m
|
71
|
+
|
72
|
+
$ iron untrust [FILE]...
|
73
|
+
|
74
|
+
\e[1mGLOBAL OPTIONS\e[0m
|
75
|
+
|
76
|
+
-h, --help
|
77
|
+
Display help documentation
|
78
|
+
|
79
|
+
-v, --version
|
80
|
+
Display version information
|
81
|
+
TXT
|
82
|
+
end
|
83
|
+
end
|
data/lib/ironment/version.rb
CHANGED
@@ -0,0 +1,141 @@
|
|
1
|
+
require "stringio"
|
2
|
+
|
3
|
+
def truncate(string, options = {})
|
4
|
+
max = options.fetch(:max, 20)
|
5
|
+
|
6
|
+
if string.length > max
|
7
|
+
"#{string[0..max]} (...)"
|
8
|
+
else
|
9
|
+
string
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_optparse_passthrough(options)
|
14
|
+
argv = options.delete(:argv)
|
15
|
+
|
16
|
+
raise ArgumentError, "Expected a single expectation" unless options.size == 1
|
17
|
+
|
18
|
+
expectation, arguments = options.first
|
19
|
+
|
20
|
+
it "should parse \"#{argv.join(" ")}\" and invoke ##{expectation} with #{arguments.inspect}" do
|
21
|
+
cl = Minitest::Mock.new
|
22
|
+
cl.expect expectation, nil, arguments
|
23
|
+
|
24
|
+
Ironment::Optparse.new(
|
25
|
+
cl: cl,
|
26
|
+
argv: argv
|
27
|
+
).parse
|
28
|
+
|
29
|
+
cl.verify
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_optparse_stdout(options)
|
34
|
+
argv, stdout = options.values_at(:argv, :stdout)
|
35
|
+
|
36
|
+
it "should parse \"#{argv.join(" ")}\" and output #{truncate(stdout).inspect}" do
|
37
|
+
actual_stdout = StringIO.new
|
38
|
+
|
39
|
+
Ironment::Optparse.new(
|
40
|
+
cl: Minitest::Mock.new, # Dummmy mock without expectations
|
41
|
+
argv: argv,
|
42
|
+
stdout: actual_stdout
|
43
|
+
).parse
|
44
|
+
|
45
|
+
assert_equal stdout, actual_stdout.string
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_optparse_stderr(options)
|
50
|
+
argv, stderr = options.values_at(:argv, :stderr)
|
51
|
+
|
52
|
+
it "should parse \"#{argv.join(" ")}\" and output #{truncate(stderr).inspect}" do
|
53
|
+
actual_stderr = StringIO.new
|
54
|
+
|
55
|
+
Ironment::Optparse.new(
|
56
|
+
cl: Minitest::Mock.new, # Dummmy mock without expectations
|
57
|
+
argv: argv,
|
58
|
+
stderr: actual_stderr
|
59
|
+
).parse
|
60
|
+
|
61
|
+
assert_equal stderr, actual_stderr.string
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_optparse_ret_value(options)
|
66
|
+
argv, ret_value = options.values_at(:argv, :ret_value)
|
67
|
+
|
68
|
+
it "should parse \"#{argv.join(" ")}\" and return #{ret_value}" do
|
69
|
+
actual_stderr = StringIO.new
|
70
|
+
|
71
|
+
actual_ret_value = Ironment::Optparse.new(
|
72
|
+
cl: Minitest::Mock.new, # Dummmy mock without expectations
|
73
|
+
argv: argv,
|
74
|
+
stdout: StringIO.new,
|
75
|
+
stderr: StringIO.new
|
76
|
+
).parse
|
77
|
+
|
78
|
+
assert_equal ret_value, actual_ret_value
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe Ironment::Optparse do
|
83
|
+
test_optparse_passthrough argv: ["foo"], exec_with_environment: ["foo"]
|
84
|
+
test_optparse_passthrough argv: ["foo", "--bar"], exec_with_environment: ["foo", "--bar"]
|
85
|
+
test_optparse_passthrough argv: ["foo", "--help"], exec_with_environment: ["foo", "--help"]
|
86
|
+
test_optparse_passthrough argv: ["exec", "foo"], exec_with_environment: ["foo"]
|
87
|
+
test_optparse_passthrough argv: ["trust", "foo"], trust: ["foo"]
|
88
|
+
test_optparse_passthrough argv: ["untrust", "foo"], untrust: ["foo"]
|
89
|
+
|
90
|
+
test_optparse_stdout argv: [], stdout: Ironment::Optparse::BASE_HELP_TEXT
|
91
|
+
test_optparse_stdout argv: ["-h"], stdout: Ironment::Optparse::BASE_HELP_TEXT
|
92
|
+
test_optparse_stdout argv: ["--help"], stdout: Ironment::Optparse::BASE_HELP_TEXT
|
93
|
+
test_optparse_stdout argv: ["help"], stdout: Ironment::Optparse::BASE_HELP_TEXT
|
94
|
+
|
95
|
+
test_optparse_stdout argv: ["exec", "-h"], stdout: Ironment::Optparse::EXEC_HELP_TEXT
|
96
|
+
test_optparse_stdout argv: ["exec", "--help"], stdout: Ironment::Optparse::EXEC_HELP_TEXT
|
97
|
+
test_optparse_stdout argv: ["help", "exec"], stdout: Ironment::Optparse::EXEC_HELP_TEXT
|
98
|
+
|
99
|
+
test_optparse_stdout argv: ["trust", "-h"], stdout: Ironment::Optparse::TRUST_HELP_TEXT
|
100
|
+
test_optparse_stdout argv: ["trust", "--help"], stdout: Ironment::Optparse::TRUST_HELP_TEXT
|
101
|
+
test_optparse_stdout argv: ["help", "trust"], stdout: Ironment::Optparse::TRUST_HELP_TEXT
|
102
|
+
|
103
|
+
test_optparse_stdout argv: ["untrust", "-h"], stdout: Ironment::Optparse::UNTRUST_HELP_TEXT
|
104
|
+
test_optparse_stdout argv: ["untrust", "--help"], stdout: Ironment::Optparse::UNTRUST_HELP_TEXT
|
105
|
+
test_optparse_stdout argv: ["help", "untrust"], stdout: Ironment::Optparse::UNTRUST_HELP_TEXT
|
106
|
+
|
107
|
+
test_optparse_stdout argv: ["-v"], stdout: "Ironment #{Ironment::VERSION}\n"
|
108
|
+
test_optparse_stdout argv: ["--version"], stdout: "Ironment #{Ironment::VERSION}\n"
|
109
|
+
|
110
|
+
test_optparse_stderr argv: ["--foo", "bar"], stderr: "Unknown option: --foo\n"
|
111
|
+
test_optparse_ret_value argv: ["--foo", "bar"], ret_value: 1
|
112
|
+
|
113
|
+
test_optparse_stderr argv: ["help", "foo"], stderr: "Unknown command: foo\n"
|
114
|
+
test_optparse_ret_value argv: ["help", "foo"], ret_value: 1
|
115
|
+
|
116
|
+
it "should invoke #trust once for each argument" do
|
117
|
+
cl = Minitest::Mock.new
|
118
|
+
cl.expect :trust, nil, ["foo"]
|
119
|
+
cl.expect :trust, nil, ["bar"]
|
120
|
+
|
121
|
+
Ironment::Optparse.new(
|
122
|
+
cl: cl,
|
123
|
+
argv: ["trust", "foo", "bar"]
|
124
|
+
).parse
|
125
|
+
|
126
|
+
cl.verify
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should invoke #untrust once for each argument" do
|
130
|
+
cl = Minitest::Mock.new
|
131
|
+
cl.expect :untrust, nil, ["foo"]
|
132
|
+
cl.expect :untrust, nil, ["bar"]
|
133
|
+
|
134
|
+
Ironment::Optparse.new(
|
135
|
+
cl: cl,
|
136
|
+
argv: ["untrust", "foo", "bar"]
|
137
|
+
).parse
|
138
|
+
|
139
|
+
cl.verify
|
140
|
+
end
|
141
|
+
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,43 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ironment
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonas Amundsen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 4.3.5
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: 4.3.5
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: codeclimate-test-reporter
|
14
|
+
name: simplecov
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
30
16
|
requirements:
|
31
17
|
- - '='
|
32
18
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.
|
19
|
+
version: 0.16.1
|
34
20
|
type: :development
|
35
21
|
prerelease: false
|
36
22
|
version_requirements: !ruby/object:Gem::Requirement
|
37
23
|
requirements:
|
38
24
|
- - '='
|
39
25
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.
|
26
|
+
version: 0.16.1
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: fakefs
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -126,6 +112,8 @@ files:
|
|
126
112
|
- lib/ironment/exec.rb
|
127
113
|
- lib/ironment/executor.rb
|
128
114
|
- lib/ironment/finder.rb
|
115
|
+
- lib/ironment/optparse.rb
|
116
|
+
- lib/ironment/optparse/help_texts.rb
|
129
117
|
- lib/ironment/populator.rb
|
130
118
|
- lib/ironment/runcom.rb
|
131
119
|
- lib/ironment/truster.rb
|
@@ -135,6 +123,7 @@ files:
|
|
135
123
|
- test/executor_test.rb
|
136
124
|
- test/finder_test.rb
|
137
125
|
- test/ironment_test.rb
|
126
|
+
- test/optparse_test.rb
|
138
127
|
- test/populator_test.rb
|
139
128
|
- test/runcom_test.rb
|
140
129
|
- test/test_helper.rb
|
@@ -159,17 +148,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
159
148
|
version: '0'
|
160
149
|
requirements: []
|
161
150
|
rubyforge_project:
|
162
|
-
rubygems_version: 2.
|
151
|
+
rubygems_version: 2.5.2
|
163
152
|
signing_key:
|
164
153
|
specification_version: 4
|
165
154
|
summary: Environment populator & command wrapper utility.
|
166
155
|
test_files:
|
167
|
-
- test/
|
168
|
-
- test/truster_test.rb
|
169
|
-
- test/runcom_test.rb
|
170
|
-
- test/cl_test.rb
|
156
|
+
- test/config_test.rb
|
171
157
|
- test/finder_test.rb
|
158
|
+
- test/test_helper.rb
|
172
159
|
- test/populator_test.rb
|
160
|
+
- test/runcom_test.rb
|
161
|
+
- test/truster_test.rb
|
173
162
|
- test/ironment_test.rb
|
174
|
-
- test/
|
175
|
-
- test/
|
163
|
+
- test/optparse_test.rb
|
164
|
+
- test/executor_test.rb
|
165
|
+
- test/cl_test.rb
|