Find process now matches on partial names and outputs all processes that match

pull/7/head
Braydon Kains 5 years ago
parent 49b5bd6822
commit 0b9302840a

@ -22,8 +22,8 @@ class LtnpOperator
@ltnp_records.find { |r| r.port == port }
end
def search_p_name(p_name : String) : LtnpRecord | Nil
@ltnp_records.find { |r| r.p_name == p_name }
def search_p_name(p_name : String) : Array(LtnpRecord)
@ltnp_records.select { |r| r.p_name.includes?(p_name) }
end
# Actions
@ -43,12 +43,12 @@ class LtnpOperator
# -p, --find-process
def find_process(p_name : String)
record = search_p_name p_name
records = search_p_name p_name
unless record.nil?
result = record.output_s
unless records.empty?
result = records.map { |record| record.output_s }.join("\n")
else
result = "No process found by the name %s" % p_name
result = "No processes found that match the name %s" % p_name
end
result

@ -8,6 +8,8 @@ describe LtnpOperator do
nonsense_port = "1234"
existing_p_name = "polymer"
partial_existing_p_name = "poly"
multiple_exist_p_name = "spotify"
nonsense_p_name = "thisisnotathing"
describe "#get_port_record" do
@ -22,11 +24,11 @@ describe LtnpOperator do
describe "#search_p_name" do
it "should find record when process exists" do
sut.search_p_name(existing_p_name).nil?.should be_false
sut.search_p_name(existing_p_name).empty?.should be_false
end
it "should not find record when process doesn't exist" do
sut.search_p_name(nonsense_p_name).nil?.should be_true
sut.search_p_name(nonsense_p_name).empty?.should be_true
end
end
@ -41,10 +43,18 @@ describe LtnpOperator do
end
describe "#find_process" do
it "should output successful message if found" do
it "should output successful message if full match found" do
sut.find_process(existing_p_name).should contain("Process:")
end
it "should output successful message if partial match found" do
sut.find_process(partial_existing_p_name).should contain("Process:")
end
it "should output every found process" do
sut.find_process(multiple_exist_p_name).each_line.size.should eq 2
end
it "should output failure message if not found" do
sut.find_process(nonsense_p_name).should contain("No")
end

Loading…
Cancel
Save