cocaine 0.0.1 → 0.0.2
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/LICENSE +26 -0
- data/README.md +77 -0
- data/lib/cocaine/command_line.rb +1 -1
- data/lib/cocaine/version.rb +1 -1
- metadata +5 -3
data/LICENSE
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
|
2
|
+
LICENSE
|
3
|
+
|
4
|
+
The MIT License
|
5
|
+
|
6
|
+
Copyright (c) 2008 Jon Yurek and thoughtbot, inc.
|
7
|
+
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
+
of this software and associated documentation files (the "Software"), to deal
|
10
|
+
in the Software without restriction, including without limitation the rights
|
11
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
12
|
+
copies of the Software, and to permit persons to whom the Software is
|
13
|
+
furnished to do so, subject to the following conditions:
|
14
|
+
|
15
|
+
The above copyright notice and this permission notice shall be included in
|
16
|
+
all copies or substantial portions of the Software.
|
17
|
+
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
21
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
24
|
+
THE SOFTWARE.
|
25
|
+
|
26
|
+
|
data/README.md
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
# Cocaine
|
2
|
+
|
3
|
+
A small library for doing (command) lines.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
The basic, normal stuff.
|
8
|
+
|
9
|
+
line = Cocaine::CommandLine.run("command", "some 'crazy' options")
|
10
|
+
line.command # => "command some 'crazy' options"
|
11
|
+
output = line.run # => Get you some output!
|
12
|
+
|
13
|
+
Allowing arguments to be dynamic.
|
14
|
+
|
15
|
+
line = Cocaine::CommandLine.new("convert", ":in -scale :resolution :out",
|
16
|
+
:in => "omg.jpg",
|
17
|
+
:resolution => "32x32",
|
18
|
+
:out => omg_thumb.jpg")
|
19
|
+
line.command # => "convert 'omg.jpg' -scale '32x32' 'omg_thumb.jpg'"
|
20
|
+
|
21
|
+
It prevents attempts at being bad.
|
22
|
+
|
23
|
+
line = Cocaine::CommandLine.new("cat", ":file", :file => "haha`rm -rf /`.txt")
|
24
|
+
line.command # => "cat 'haha`rm -rf /`.txt'"
|
25
|
+
|
26
|
+
line = Cocaine::CommandLine.new("cat", ":file", :file => "ohyeah?'`rm -rf /`.ha!")
|
27
|
+
line.command # => "cat 'ohyeah?'\\''`rm -rf /`.ha!'"
|
28
|
+
|
29
|
+
You can ignore the result.
|
30
|
+
|
31
|
+
line = Cocaine::CommandLine.new("noisy", "--extra-verbose", :swallow_stderr => true)
|
32
|
+
line.command # => "noisy --extra-verbose 2>/dev/null"
|
33
|
+
|
34
|
+
# ... and on Windows...
|
35
|
+
line.command # => "noisy --extra-verbose 2>NUL"
|
36
|
+
|
37
|
+
If your command errors, you get an exception.
|
38
|
+
|
39
|
+
line = Cocaine::CommandLine.new("git", "commit")
|
40
|
+
begin
|
41
|
+
line.run
|
42
|
+
rescue Cocaine::ExitStatusError => e
|
43
|
+
e.message # => "Command 'git commit' returned 1. Expected 0"
|
44
|
+
end
|
45
|
+
|
46
|
+
You don't have the command? You get an exception.
|
47
|
+
|
48
|
+
line = Cocaine::CommandLine.new("lolwut")
|
49
|
+
begin
|
50
|
+
line.run
|
51
|
+
rescue Cocaine::CommandNotFoundError => e
|
52
|
+
e # => the command isn't in the $PATH for this process.
|
53
|
+
end
|
54
|
+
|
55
|
+
But don't fear, you can specify where to look for the command.
|
56
|
+
|
57
|
+
Cocaine::CommandLine.path = "/opt/bin"
|
58
|
+
line = Cocaine::CommandLine.new("lolwut")
|
59
|
+
line.command # => "/opt/bin/lolwut"
|
60
|
+
|
61
|
+
Or, just, you know, put it in the command.
|
62
|
+
|
63
|
+
line = Cocaine::CommandLine.new("/opt/bin/lolwut")
|
64
|
+
line.command # => "/opt/bin/lolwut"
|
65
|
+
|
66
|
+
If your command might return something non-zero, and you expect that, it's cool.
|
67
|
+
|
68
|
+
line = Cocaine::CommandLine.new("/usr/bin/false", "", :expected_outcodes => [0, 1])
|
69
|
+
begin
|
70
|
+
line.run
|
71
|
+
rescue Cocaine::ExitStatusError => e
|
72
|
+
# => You never get here!
|
73
|
+
end
|
74
|
+
|
75
|
+
## License
|
76
|
+
|
77
|
+
Copyright 2011 Jon Yurek and thoughtbot, inc. This is free software, and may be redistributed under the terms specified in the LICENSE file.
|
data/lib/cocaine/command_line.rb
CHANGED
@@ -8,7 +8,7 @@ module Cocaine
|
|
8
8
|
@binary = binary.dup
|
9
9
|
@params = params.dup
|
10
10
|
@options = options.dup
|
11
|
-
@swallow_stderr = @options.
|
11
|
+
@swallow_stderr = @options.delete(:swallow_stderr)
|
12
12
|
@expected_outcodes = @options.delete(:expected_outcodes)
|
13
13
|
@expected_outcodes ||= [0]
|
14
14
|
end
|
data/lib/cocaine/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cocaine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jon Yurek
|
@@ -69,6 +69,8 @@ extensions: []
|
|
69
69
|
extra_rdoc_files: []
|
70
70
|
|
71
71
|
files:
|
72
|
+
- README.md
|
73
|
+
- LICENSE
|
72
74
|
- Rakefile
|
73
75
|
- lib/cocaine.rb
|
74
76
|
- lib/cocaine/command_line.rb
|