sh 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.rbenv-version +1 -0
- data/README.md +19 -0
- data/Rakefile +11 -0
- data/lib/sh.rb +5 -9
- data/lib/sh/version.rb +1 -1
- data/sh.gemspec +3 -0
- data/spec/cmd_spec.rb +33 -0
- data/spec/spec_helper.rb +5 -0
- metadata +32 -10
data/.rbenv-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.9.2-p290
|
data/README.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Sh::Cmd
|
2
|
+
|
3
|
+
Sh::Cmd is useful for constructing large Sh commands programmatically.
|
4
|
+
It also has the benefit of Shell escaping any args you pass.
|
5
|
+
|
6
|
+
## Usage:
|
7
|
+
|
8
|
+
``` ruby
|
9
|
+
cmd = Sh::Cmd.new("git") do |c|
|
10
|
+
c.arg "log"
|
11
|
+
c.opt "--oneline"
|
12
|
+
end
|
13
|
+
|
14
|
+
# OR
|
15
|
+
|
16
|
+
cmd = Sh::Cmd.new("git").arg("log").opt("--oneline")
|
17
|
+
|
18
|
+
puts cmd # => "git log --oneline"
|
19
|
+
```
|
data/Rakefile
CHANGED
data/lib/sh.rb
CHANGED
@@ -2,7 +2,7 @@ require "sh/version"
|
|
2
2
|
require "escape"
|
3
3
|
|
4
4
|
# Sh::Cmd is useful for constructing large Sh commands programmatically.
|
5
|
-
# It also has the benefit of
|
5
|
+
# It also has the benefit of Shell escaping any args you pass.
|
6
6
|
#
|
7
7
|
# Usage:
|
8
8
|
#
|
@@ -13,14 +13,14 @@ require "escape"
|
|
13
13
|
#
|
14
14
|
# # OR
|
15
15
|
#
|
16
|
-
# cmd = Sh::Cmd.new("git").arg("log").opt("--
|
16
|
+
# cmd = Sh::Cmd.new("git").arg("log").opt("--oneline")
|
17
17
|
#
|
18
18
|
# puts cmd # => "git log --oneline"
|
19
19
|
|
20
20
|
module Sh
|
21
21
|
class Cmd
|
22
22
|
def initialize(cmd="")
|
23
|
-
@cmd, @args
|
23
|
+
@cmd, @args = cmd, []
|
24
24
|
yield self if block_given?
|
25
25
|
end
|
26
26
|
|
@@ -28,14 +28,10 @@ module Sh
|
|
28
28
|
@args += args
|
29
29
|
self
|
30
30
|
end
|
31
|
-
|
32
|
-
def opt(*opts)
|
33
|
-
@opts += opts
|
34
|
-
self
|
35
|
-
end
|
31
|
+
alias_method :opt, :arg
|
36
32
|
|
37
33
|
def to_s
|
38
|
-
[ @cmd ].concat(@args).
|
34
|
+
[ @cmd ].concat(@args).map(&:to_s).map { |w| escape(w) }.join(' ')
|
39
35
|
end
|
40
36
|
|
41
37
|
def exec
|
data/lib/sh/version.rb
CHANGED
data/sh.gemspec
CHANGED
@@ -21,5 +21,8 @@ Gem::Specification.new do |s|
|
|
21
21
|
# specify any dependencies here; for example:
|
22
22
|
# s.add_development_dependency "rspec"
|
23
23
|
# s.add_runtime_dependency "rest-client"
|
24
|
+
|
25
|
+
s.add_runtime_dependency "escape"
|
24
26
|
s.add_development_dependency "rake"
|
27
|
+
s.add_development_dependency "minitest", "~> 2.8.1"
|
25
28
|
end
|
data/spec/cmd_spec.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Sh::Cmd do
|
4
|
+
# it "can accept a csv path" do
|
5
|
+
# table = Crunch.table( File.expand_path("../data/test.csv", __FILE__) )
|
6
|
+
# table.first['domain'].must_equal "example.com"
|
7
|
+
# end
|
8
|
+
|
9
|
+
it "can build a shell command with a block" do
|
10
|
+
cmd = Sh::Cmd.new("git") do |c|
|
11
|
+
c.arg "log"
|
12
|
+
c.opt "--oneline"
|
13
|
+
end
|
14
|
+
|
15
|
+
cmd.to_s.must_equal "git log --oneline"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "can build a shell command with a chain" do
|
19
|
+
cmd = Sh::Cmd.new("git").arg("log").opt("--oneline")
|
20
|
+
cmd.to_s.must_equal "git log --oneline"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "can string args and opts together in any order" do
|
24
|
+
cmd = Sh::Cmd.new("git").arg("log").opt("--oneline").opt("decorate=full").arg("since...until").opt("--").arg("pathname")
|
25
|
+
cmd.to_s.must_equal "git log --oneline decorate=full since...until -- pathname"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "can take multiple args or opts at once" do
|
29
|
+
cmd = Sh::Cmd.new("git").arg("log").opt("--oneline", "decorate=full").arg("since...until", "--", "pathname")
|
30
|
+
cmd.to_s.must_equal "git log --oneline decorate=full since...until -- pathname"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,9 +11,20 @@ bindir: bin
|
|
11
11
|
cert_chain: []
|
12
12
|
date: 2011-11-28 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: escape
|
16
|
+
requirement: &2161318240 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2161318240
|
14
25
|
- !ruby/object:Gem::Dependency
|
15
26
|
name: rake
|
16
|
-
requirement: &
|
27
|
+
requirement: &2161317580 !ruby/object:Gem::Requirement
|
17
28
|
none: false
|
18
29
|
requirements:
|
19
30
|
- - ! '>='
|
@@ -21,7 +32,18 @@ dependencies:
|
|
21
32
|
version: '0'
|
22
33
|
type: :development
|
23
34
|
prerelease: false
|
24
|
-
version_requirements: *
|
35
|
+
version_requirements: *2161317580
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: minitest
|
38
|
+
requirement: &2161316700 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 2.8.1
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2161316700
|
25
47
|
description: A nice API for constructing complex shell commands
|
26
48
|
email:
|
27
49
|
- bmarini@gmail.com
|
@@ -30,11 +52,15 @@ extensions: []
|
|
30
52
|
extra_rdoc_files: []
|
31
53
|
files:
|
32
54
|
- .gitignore
|
55
|
+
- .rbenv-version
|
33
56
|
- Gemfile
|
57
|
+
- README.md
|
34
58
|
- Rakefile
|
35
59
|
- lib/sh.rb
|
36
60
|
- lib/sh/version.rb
|
37
61
|
- sh.gemspec
|
62
|
+
- spec/cmd_spec.rb
|
63
|
+
- spec/spec_helper.rb
|
38
64
|
homepage: ''
|
39
65
|
licenses: []
|
40
66
|
post_install_message:
|
@@ -47,22 +73,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
47
73
|
- - ! '>='
|
48
74
|
- !ruby/object:Gem::Version
|
49
75
|
version: '0'
|
50
|
-
segments:
|
51
|
-
- 0
|
52
|
-
hash: -2663379127003520870
|
53
76
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
77
|
none: false
|
55
78
|
requirements:
|
56
79
|
- - ! '>='
|
57
80
|
- !ruby/object:Gem::Version
|
58
81
|
version: '0'
|
59
|
-
segments:
|
60
|
-
- 0
|
61
|
-
hash: -2663379127003520870
|
62
82
|
requirements: []
|
63
83
|
rubyforge_project: sh
|
64
84
|
rubygems_version: 1.8.10
|
65
85
|
signing_key:
|
66
86
|
specification_version: 3
|
67
87
|
summary: A nice API for constructing complex shell commands
|
68
|
-
test_files:
|
88
|
+
test_files:
|
89
|
+
- spec/cmd_spec.rb
|
90
|
+
- spec/spec_helper.rb
|