Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #1 from jjb/patch-1

pretty syntax highlighting
  • Loading branch information...
commit 515093950445fb8e5d58f8f252355e9df32240b7 2 parents 7f11075 + 0f60aee
@jyurek jyurek authored
Showing with 57 additions and 39 deletions.
  1. +57 −39 README.md
View
96 README.md
@@ -12,71 +12,89 @@ Question? Idea? Problem? Bug? Something else? Comment? Concern? Like use questio
The basic, normal stuff.
- line = Cocaine::CommandLine.run("command", "some 'crazy' options")
- line.command # => "command some 'crazy' options"
- output = line.run # => Get you some output!
+```ruby
+line = Cocaine::CommandLine.run("command", "some 'crazy' options")
+line.command # => "command some 'crazy' options"
+output = line.run # => Get you some output!
+```
Allowing arguments to be dynamic.
- line = Cocaine::CommandLine.new("convert", ":in -scale :resolution :out",
- :in => "omg.jpg",
- :resolution => "32x32",
- :out => omg_thumb.jpg")
- line.command # => "convert 'omg.jpg' -scale '32x32' 'omg_thumb.jpg'"
+```ruby
+line = Cocaine::CommandLine.new("convert", ":in -scale :resolution :out",
+ :in => "omg.jpg",
+ :resolution => "32x32",
+ :out => omg_thumb.jpg")
+line.command # => "convert 'omg.jpg' -scale '32x32' 'omg_thumb.jpg'"
+```
It prevents attempts at being bad.
- line = Cocaine::CommandLine.new("cat", ":file", :file => "haha`rm -rf /`.txt")
- line.command # => "cat 'haha`rm -rf /`.txt'"
+```ruby
+line = Cocaine::CommandLine.new("cat", ":file", :file => "haha`rm -rf /`.txt")
+line.command # => "cat 'haha`rm -rf /`.txt'"
- line = Cocaine::CommandLine.new("cat", ":file", :file => "ohyeah?'`rm -rf /`.ha!")
- line.command # => "cat 'ohyeah?'\\''`rm -rf /`.ha!'"
+line = Cocaine::CommandLine.new("cat", ":file", :file => "ohyeah?'`rm -rf /`.ha!")
+line.command # => "cat 'ohyeah?'\\''`rm -rf /`.ha!'"
+```
You can ignore the result.
- line = Cocaine::CommandLine.new("noisy", "--extra-verbose", :swallow_stderr => true)
- line.command # => "noisy --extra-verbose 2>/dev/null"
+```ruby
+line = Cocaine::CommandLine.new("noisy", "--extra-verbose", :swallow_stderr => true)
+line.command # => "noisy --extra-verbose 2>/dev/null"
- # ... and on Windows...
- line.command # => "noisy --extra-verbose 2>NUL"
+# ... and on Windows...
+line.command # => "noisy --extra-verbose 2>NUL"
+```
If your command errors, you get an exception.
- line = Cocaine::CommandLine.new("git", "commit")
- begin
- line.run
- rescue Cocaine::ExitStatusError => e
- e.message # => "Command 'git commit' returned 1. Expected 0"
- end
+```ruby
+line = Cocaine::CommandLine.new("git", "commit")
+begin
+ line.run
+rescue Cocaine::ExitStatusError => e
+ e.message # => "Command 'git commit' returned 1. Expected 0"
+end
+```
You don't have the command? You get an exception.
- line = Cocaine::CommandLine.new("lolwut")
- begin
- line.run
- rescue Cocaine::CommandNotFoundError => e
- e # => the command isn't in the $PATH for this process.
- end
+```ruby
+line = Cocaine::CommandLine.new("lolwut")
+begin
+ line.run
+rescue Cocaine::CommandNotFoundError => e
+ e # => the command isn't in the $PATH for this process.
+end
+```
But don't fear, you can specify where to look for the command.
- Cocaine::CommandLine.path = "/opt/bin"
- line = Cocaine::CommandLine.new("lolwut")
- line.command # => "/opt/bin/lolwut"
+```ruby
+Cocaine::CommandLine.path = "/opt/bin"
+line = Cocaine::CommandLine.new("lolwut")
+line.command # => "/opt/bin/lolwut"
+```
Or, just, you know, put it in the command.
- line = Cocaine::CommandLine.new("/opt/bin/lolwut")
- line.command # => "/opt/bin/lolwut"
+```ruby
+line = Cocaine::CommandLine.new("/opt/bin/lolwut")
+line.command # => "/opt/bin/lolwut"
+```
If your command might return something non-zero, and you expect that, it's cool.
- line = Cocaine::CommandLine.new("/usr/bin/false", "", :expected_outcodes => [0, 1])
- begin
- line.run
- rescue Cocaine::ExitStatusError => e
- # => You never get here!
- end
+```ruby
+line = Cocaine::CommandLine.new("/usr/bin/false", "", :expected_outcodes => [0, 1])
+begin
+ line.run
+rescue Cocaine::ExitStatusError => e
+ # => You never get here!
+end
+```
## License
Please sign in to comment.
Something went wrong with that request. Please try again.