@@ -12,71 +12,89 @@ Question? Idea? Problem? Bug? Something else? Comment? Concern? Like use questio
1212
1313The basic, normal stuff.
1414
15- line = Cocaine::CommandLine.run("command", "some 'crazy' options")
16- line.command # => "command some 'crazy' options"
17- output = line.run # => Get you some output!
15+ ``` ruby
16+ line = Cocaine ::CommandLine .run(" command" , " some 'crazy' options" )
17+ line.command # => "command some 'crazy' options"
18+ output = line.run # => Get you some output!
19+ ```
1820
1921Allowing arguments to be dynamic.
2022
21- line = Cocaine::CommandLine.new("convert", ":in -scale :resolution :out",
22- :in => "omg.jpg",
23- :resolution => "32x32",
24- :out => omg_thumb.jpg")
25- line.command # => "convert 'omg.jpg' -scale '32x32' 'omg_thumb.jpg'"
23+ ``` ruby
24+ line = Cocaine ::CommandLine .new (" convert" , " :in -scale :resolution :out" ,
25+ :in => " omg.jpg" ,
26+ :resolution => " 32x32" ,
27+ :out => omg_thumb.jpg" )
28+ line.command # => " convert ' omg.jpg' - scale ' 32x32' ' omg_thumb.jpg' "
29+ ```
2630
2731It prevents attempts at being bad.
2832
29- line = Cocaine::CommandLine.new("cat", ":file", :file => "haha`rm -rf /`.txt")
30- line.command # => "cat 'haha`rm -rf /`.txt'"
33+ ```ruby
34+ line = Cocaine::CommandLine.new(" cat" , " :file " , :file => " haha` rm -rf /` .txt" )
35+ line.command # => " cat ' haha`rm -rf /`.txt' "
3136
32- line = Cocaine::CommandLine.new("cat", ":file", :file => "ohyeah?'`rm -rf /`.ha!")
33- line.command # => "cat 'ohyeah?'\\''`rm -rf /`.ha!'"
37+ line = Cocaine::CommandLine.new(" cat" , " :file " , :file => " ohyeah?' `rm -rf /`.ha!")
38+ line.command # => "cat ' ohyeah?' \\ ' ' `rm -rf /`.ha!' "
39+ ```
3440
3541You can ignore the result.
3642
37- line = Cocaine::CommandLine.new("noisy", "--extra-verbose", :swallow_stderr => true)
38- line.command # => "noisy --extra-verbose 2>/dev/null"
43+ ```ruby
44+ line = Cocaine::CommandLine.new(" noisy" , " -- extra- verbose" , :swallow_stderr => true)
45+ line.command # => " noisy -- extra- verbose 2 > / dev/ null"
3946
40- # ... and on Windows...
41- line.command # => "noisy --extra-verbose 2>NUL"
47+ # ... and on Windows...
48+ line.command # => " noisy -- extra- verbose 2 > NUL "
49+ ```
4250
4351If your command errors, you get an exception.
4452
45- line = Cocaine::CommandLine.new("git", "commit")
46- begin
47- line.run
48- rescue Cocaine::ExitStatusError => e
49- e.message # => "Command 'git commit' returned 1. Expected 0"
50- end
53+ ```ruby
54+ line = Cocaine::CommandLine.new(" git" , " commit" )
55+ begin
56+ line.run
57+ rescue Cocaine::ExitStatusError => e
58+ e.message # => " Command ' git commit' returned 1 . Expected 0 "
59+ end
60+ ```
5161
5262You don't have the command? You get an exception.
5363
54- line = Cocaine::CommandLine.new("lolwut")
55- begin
56- line.run
57- rescue Cocaine::CommandNotFoundError => e
58- e # => the command isn't in the $PATH for this process.
59- end
64+ ```ruby
65+ line = Cocaine::CommandLine.new(" lolwut" )
66+ begin
67+ line.run
68+ rescue Cocaine::CommandNotFoundError => e
69+ e # => the command isn't in the $PATH for this process.
70+ end
71+ ```
6072
6173But don't fear, you can specify where to look for the command.
6274
63- Cocaine::CommandLine.path = "/opt/bin"
64- line = Cocaine::CommandLine.new("lolwut")
65- line.command # => "/opt/bin/lolwut"
75+ ```ruby
76+ Cocaine::CommandLine.path = " / opt/ bin"
77+ line = Cocaine::CommandLine.new(" lolwut" )
78+ line.command # => " / opt/ bin/ lolwut"
79+ ```
6680
6781Or, just, you know, put it in the command.
6882
69- line = Cocaine::CommandLine.new("/opt/bin/lolwut")
70- line.command # => "/opt/bin/lolwut"
83+ ```ruby
84+ line = Cocaine::CommandLine.new(" / opt/ bin/ lolwut" )
85+ line.command # => " / opt/ bin/ lolwut"
86+ ```
7187
7288If your command might return something non-zero, and you expect that, it's cool.
7389
74- line = Cocaine::CommandLine.new("/usr/bin/false", "", :expected_outcodes => [0, 1])
75- begin
76- line.run
77- rescue Cocaine::ExitStatusError => e
78- # => You never get here!
79- end
90+ ```ruby
91+ line = Cocaine::CommandLine.new(" / usr/ bin/ false " , " " , :expected_outcodes => [0, 1])
92+ begin
93+ line.run
94+ rescue Cocaine::ExitStatusError => e
95+ # => You never get here!
96+ end
97+ ```
8098
8199## License
82100
0 commit comments