sh 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ 1.9.2-p290
@@ -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
@@ -1 +1,12 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ task :default => [:test]
5
+
6
+ task :test do
7
+ Rake::TestTask.new do |t|
8
+ t.libs << "spec"
9
+ t.pattern = 'spec/*_spec.rb'
10
+ t.verbose = true
11
+ end
12
+ end
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 Sh escaping any args you pass.
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("--online")
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, @opts = cmd, [], []
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).concat(@opts).map(&:to_s).map { |w| escape(w) }.join(' ')
34
+ [ @cmd ].concat(@args).map(&:to_s).map { |w| escape(w) }.join(' ')
39
35
  end
40
36
 
41
37
  def exec
@@ -1,3 +1,3 @@
1
1
  module Sh
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
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
@@ -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
+
@@ -0,0 +1,5 @@
1
+ require "rubygems"
2
+ require "bundler/setup"
3
+ require "minitest/autorun"
4
+ require "sh"
5
+
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.1
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: &2169505320 !ruby/object:Gem::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: *2169505320
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