Skip to content

Commit 565355a

Browse files
committed
fix: add chomp option for output method
1 parent 69ae424 commit 565355a

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

shard.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: exec
2-
version: 0.1.0
2+
version: 0.1.1
33

44
authors:
55
- initdc <initd@outlook.com>

spec/exec_spec.cr

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ describe Exec do
2121
Exec.output("uname").should eq "Linux"
2222
end
2323

24+
it "get Linux\n" do
25+
Exec.output("uname", false).should eq "Linux\n"
26+
end
27+
2428
it "log to file" do
2529
tempfile = File.tempfile("test_", ".log")
2630
Exec.run("uname", output: File.open(tempfile.path, "a+"))

src/exec.cr

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class Exec < Process
2-
VERSION = "0.1.0"
2+
VERSION = "0.1.1"
33

44
def self.run(command : String, args = nil, env : Env = nil, clear_env : Bool = false, shell : Bool = true,
55
input : Stdio = Redirect::Inherit, output : Stdio = Redirect::Inherit, error : Stdio = Redirect::Inherit, chdir : Path | String? = nil) : Process::Status
@@ -17,12 +17,13 @@ class Exec < Process
1717
127
1818
end
1919

20-
def self.output(command) : String
20+
def self.output(command, chomp = true) : String
2121
process = new(command, shell: true, input: Redirect::Inherit, output: Redirect::Pipe, error: Redirect::Inherit)
2222
output = process.output.gets_to_end
2323
status = process.wait
2424
$? = status
25-
output.chomp
25+
return output.chomp if chomp
26+
output
2627
end
2728

2829
def self.each_line(command, chomp = false, &block : String ->) : Nil

0 commit comments

Comments
 (0)