sh 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.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -0
- data/lib/sh.rb +50 -0
- data/lib/sh/version.rb +3 -0
- data/sh.gemspec +25 -0
- metadata +68 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/sh.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require "sh/version"
|
2
|
+
require "escape"
|
3
|
+
|
4
|
+
# Sh::Cmd is useful for constructing large Sh commands programmatically.
|
5
|
+
# It also has the benefit of Sh escaping any args you pass.
|
6
|
+
#
|
7
|
+
# Usage:
|
8
|
+
#
|
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("--online")
|
17
|
+
#
|
18
|
+
# puts cmd # => "git log --oneline"
|
19
|
+
|
20
|
+
module Sh
|
21
|
+
class Cmd
|
22
|
+
def initialize(cmd="")
|
23
|
+
@cmd, @args, @opts = cmd, [], []
|
24
|
+
yield self if block_given?
|
25
|
+
end
|
26
|
+
|
27
|
+
def arg(*args)
|
28
|
+
@args += args
|
29
|
+
self
|
30
|
+
end
|
31
|
+
|
32
|
+
def opt(*opts)
|
33
|
+
@opts += opts
|
34
|
+
self
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_s
|
38
|
+
[ @cmd ].concat(@args).concat(@opts).map(&:to_s).map { |w| escape(w) }.join(' ')
|
39
|
+
end
|
40
|
+
|
41
|
+
def exec
|
42
|
+
`#{self.to_s}`
|
43
|
+
end
|
44
|
+
|
45
|
+
# http://stackoverflow.com/questions/1306680/Shwords-Shescape-implementation-for-ruby-1-8
|
46
|
+
def escape(str)
|
47
|
+
Escape.shell_single_word(str).to_s
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/sh/version.rb
ADDED
data/sh.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "sh/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "sh"
|
7
|
+
s.version = Sh::VERSION
|
8
|
+
s.authors = ["Ben Marini"]
|
9
|
+
s.email = ["bmarini@gmail.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{A nice API for constructing complex shell commands}
|
12
|
+
s.description = %q{A nice API for constructing complex shell commands}
|
13
|
+
|
14
|
+
s.rubyforge_project = "sh"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
# s.add_development_dependency "rspec"
|
23
|
+
# s.add_runtime_dependency "rest-client"
|
24
|
+
s.add_development_dependency "rake"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sh
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ben Marini
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-11-28 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: &2169505320 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2169505320
|
25
|
+
description: A nice API for constructing complex shell commands
|
26
|
+
email:
|
27
|
+
- bmarini@gmail.com
|
28
|
+
executables: []
|
29
|
+
extensions: []
|
30
|
+
extra_rdoc_files: []
|
31
|
+
files:
|
32
|
+
- .gitignore
|
33
|
+
- Gemfile
|
34
|
+
- Rakefile
|
35
|
+
- lib/sh.rb
|
36
|
+
- lib/sh/version.rb
|
37
|
+
- sh.gemspec
|
38
|
+
homepage: ''
|
39
|
+
licenses: []
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ! '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
segments:
|
51
|
+
- 0
|
52
|
+
hash: -2663379127003520870
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
segments:
|
60
|
+
- 0
|
61
|
+
hash: -2663379127003520870
|
62
|
+
requirements: []
|
63
|
+
rubyforge_project: sh
|
64
|
+
rubygems_version: 1.8.10
|
65
|
+
signing_key:
|
66
|
+
specification_version: 3
|
67
|
+
summary: A nice API for constructing complex shell commands
|
68
|
+
test_files: []
|