exec 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +22 -0
- data/exec.gemspec +17 -0
- data/lib/exec.rb +37 -10
- data/lib/exec/version.rb +4 -0
- data/spec/lib/exec_spec.rb +65 -0
- metadata +7 -3
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
|
2
|
+
require 'exec/version'
|
3
|
+
require 'exec'
|
4
|
+
|
5
|
+
task :build do
|
6
|
+
Exec.system_v "gem build exec.gemspec"
|
7
|
+
end
|
8
|
+
|
9
|
+
task :release => :build do
|
10
|
+
Exec.system_v "gem push exec-#{Exec::VERSION}.gem"
|
11
|
+
end
|
12
|
+
|
13
|
+
task :install => :build do
|
14
|
+
Exec.system_v "gem install exec-#{Exec::VERSION}.gem"
|
15
|
+
end
|
16
|
+
|
17
|
+
task :tag do
|
18
|
+
v = Exec::VERSION.gsub(/\./, '_')
|
19
|
+
Exec.system_v "git tag REL_#{v}"
|
20
|
+
Exec.system_v "git push origin REL_#{v}"
|
21
|
+
end
|
22
|
+
|
data/exec.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
lib = File.expand_path('../lib/', __FILE__)
|
2
|
+
$:.unshift lib unless $:.include?(lib)
|
3
|
+
|
4
|
+
require 'exec/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = 'exec'
|
8
|
+
s.version = Exec::VERSION
|
9
|
+
s.date = '2011-12-19'
|
10
|
+
s.summary = 'A mix between Kernel#system and FileUtils'
|
11
|
+
s.description = 'Exec#system Exec#system_v Exec#system! Exec#system_v!'
|
12
|
+
s.authors = ['Morgan Christiansson']
|
13
|
+
s.email = 'executils@mog.se'
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.homepage = 'http://github.com/morganchristiansson/exec'
|
16
|
+
end
|
17
|
+
|
data/lib/exec.rb
CHANGED
@@ -1,18 +1,45 @@
|
|
1
1
|
module Exec
|
2
|
-
class
|
2
|
+
class NonZeroExitCodeException < Exception
|
3
3
|
def initialize
|
4
4
|
end
|
5
5
|
end
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
def self.system_v!(cmd)
|
10
|
-
$stderr.puts cmd
|
11
|
-
system(cmd) or raise NonZeroExitException
|
6
|
+
class CommandNotFoundException < Exception
|
7
|
+
def initialize
|
8
|
+
end
|
12
9
|
end
|
13
|
-
|
14
|
-
|
15
|
-
system(
|
10
|
+
class << self
|
11
|
+
alias :_system :system
|
12
|
+
def system(*args)
|
13
|
+
_system(*args)
|
14
|
+
case _system(*args)
|
15
|
+
when true ; true
|
16
|
+
when nil ; raise CommandNotFoundException
|
17
|
+
else $?.exitstatus
|
18
|
+
end
|
19
|
+
end
|
20
|
+
def system_v(*args)
|
21
|
+
$stderr.puts(*args)
|
22
|
+
case _system(*args)
|
23
|
+
when true ; true
|
24
|
+
when nil ; raise CommandNotFoundException
|
25
|
+
else $?.exitstatus
|
26
|
+
end
|
27
|
+
end
|
28
|
+
def system!(*args)
|
29
|
+
case _system(*args)
|
30
|
+
when true ; true
|
31
|
+
when nil ; raise CommandNotFoundException
|
32
|
+
else ; raise NonZeroExitCodeException
|
33
|
+
end
|
34
|
+
end
|
35
|
+
def system_v!(*args)
|
36
|
+
$stderr.puts(*args)
|
37
|
+
case _system(*args)
|
38
|
+
when true ; true
|
39
|
+
when nil ; raise CommandNotFoundException
|
40
|
+
else ; raise NonZeroExitCodeException
|
41
|
+
end
|
42
|
+
end
|
16
43
|
end
|
17
44
|
end
|
18
45
|
|
data/lib/exec/version.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'exec'
|
2
|
+
|
3
|
+
describe Exec do
|
4
|
+
subject { Exec }
|
5
|
+
before do
|
6
|
+
$stderr.stub! :puts
|
7
|
+
end
|
8
|
+
|
9
|
+
describe '#system' do
|
10
|
+
context "with successful completion" do
|
11
|
+
specify { Exec.system("true").should == true }
|
12
|
+
end
|
13
|
+
context "with non-zero exit code" do
|
14
|
+
specify { Exec.system("false").should == 1 }
|
15
|
+
end
|
16
|
+
context "with unknown command" do
|
17
|
+
specify { expect { Exec.system("afuiaerarhcfjk") }.should raise_error ::Exec::CommandNotFoundException }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#system_v' do
|
22
|
+
it "prints the command" do
|
23
|
+
$stderr.should_receive(:puts).with("true")
|
24
|
+
Exec.system_v("true")
|
25
|
+
end
|
26
|
+
context "with successful completion" do
|
27
|
+
specify { Exec.system("true").should == true }
|
28
|
+
end
|
29
|
+
context "with non-zero exit code" do
|
30
|
+
specify { Exec.system_v("false").should == 1 }
|
31
|
+
end
|
32
|
+
context "with unknown command" do
|
33
|
+
specify { expect { Exec.system_v("afuiaerarhcfjk") }.should raise_error ::Exec::CommandNotFoundException }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#system!' do
|
38
|
+
context "with successful completion" do
|
39
|
+
specify { Exec.system!("true").should == true }
|
40
|
+
end
|
41
|
+
context "with non-zero exit code" do
|
42
|
+
specify { expect { Exec.system!("false") }.should raise_error ::Exec::NonZeroExitCodeException }
|
43
|
+
end
|
44
|
+
context "with unknown command" do
|
45
|
+
specify { expect { Exec.system!("afguiauar") }.should raise_error ::Exec::CommandNotFoundException }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '#system_v!#' do
|
50
|
+
it "prints the command" do
|
51
|
+
$stderr.should_receive(:puts).with("true")
|
52
|
+
Exec.system_v!("true")
|
53
|
+
end
|
54
|
+
context "with successful completion" do
|
55
|
+
specify { Exec.system_v!("true").should == true }
|
56
|
+
end
|
57
|
+
context "with non-zero exit code" do
|
58
|
+
specify { expect { Exec.system_v!("false") }.should raise_error ::Exec::NonZeroExitCodeException }
|
59
|
+
end
|
60
|
+
context "with unknown command" do
|
61
|
+
specify { expect { Exec.system!("asdfasdf") }.should raise_error ::Exec::CommandNotFoundException }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: exec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,14 +11,18 @@ bindir: bin
|
|
11
11
|
cert_chain: []
|
12
12
|
date: 2011-12-19 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
|
-
description:
|
14
|
+
description: Exec#system Exec#system_v Exec#system! Exec#system_v!
|
15
15
|
email: executils@mog.se
|
16
16
|
executables: []
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
|
+
- Rakefile
|
21
|
+
- exec.gemspec
|
20
22
|
- lib/exec.rb
|
21
|
-
|
23
|
+
- lib/exec/version.rb
|
24
|
+
- spec/lib/exec_spec.rb
|
25
|
+
homepage: http://github.com/morganchristiansson/exec
|
22
26
|
licenses: []
|
23
27
|
post_install_message:
|
24
28
|
rdoc_options: []
|