Merge pull request #4 from BraydonKains/FindProcess

Can check for process by name
pull/5/head
Braydon Kains 5 years ago committed by GitHub
commit e7093f6752
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -17,14 +17,15 @@ Get the name and process ID of the process running on a given port
Check the process running on a given port with the option to kill it if you'd like. Check the process running on a given port with the option to kill it if you'd like.
## TODO ## TODO
* [x] Add the ability to kill process on port [x] Add the ability to kill process on port
* [] Maybe look into other cli operations? (getting IP?) [x] Add the ability to search for process by name
* [] Come up with other useful stuff [] Maybe look into other cli operations? (getting IP?)
* [] Write up contributors guide [] Come up with other useful stuff
* [] Decide how to do documentation (probably Github wiki?) [] Write up contributors guide
* [] Write man page (figure out how to do that lol) [] Decide how to do documentation (probably Github wiki?)
* [] Figure out distribution/release [] Write man page (figure out how to do that lol)
* [x] Set up CI (probably Travis) [] Figure out distribution/release
[x] Set up CI (probably Travis)
## Contributing ## Contributing
I don't know that I'm ready for contributors yet because I don't have a good contributors guide. I do plan to eventually open this up to contributors. If you have any ideas for future operations, please feel free to open an issue, I am happy to discuss ideas! I don't know that I'm ready for contributors yet because I don't have a good contributors guide. I do plan to eventually open this up to contributors. If you have any ideas for future operations, please feel free to open an issue, I am happy to discuss ideas!

@ -15,4 +15,8 @@ class LtnpOperator
def get_port_record(port : String) : LtnpRecord | Nil def get_port_record(port : String) : LtnpRecord | Nil
@ltnp_records.find { |r| r.port == port } @ltnp_records.find { |r| r.port == port }
end end
def search_p_name(p_name : String) : LtnpRecord | Nil
@ltnp_records.find { |r| r.p_name == p_name }
end
end end

@ -27,6 +27,10 @@ class LtnpRecord
] ]
end end
def out_s
"Port: %s, Process: %s, Process ID: %s" % [self.port, self.p_name, self.pid]
end
def ser_address_port(address_port : Array) : {String, String} def ser_address_port(address_port : Array) : {String, String}
address = String.new address = String.new
port = String.new port = String.new

@ -20,7 +20,7 @@ OptionParser.parse do |parser|
record = ltnp_operator.get_port_record port record = ltnp_operator.get_port_record port
unless record.nil? unless record.nil?
puts "Port: %s, Process: %s, Process ID: %s" % [record.port, record.p_name, record.pid] puts record.out_s
else else
puts "No processes found on port %s" % port puts "No processes found on port %s" % port
end end
@ -28,12 +28,25 @@ OptionParser.parse do |parser|
exit exit
end end
parser.on "-p PNAME", "--find-process=PNAME", "Find the port and ID of a process by name" do |p_name|
ltnp_operator = CommandRunner.run_ltnp
record = ltnp_operator.search_p_name p_name
unless record.nil?
puts record.out_s
else
puts "No process found by the name %s" % p_name
end
exit
end
parser.on "-k PORT", "--kill-port=PORT", "Kill process on port" do |port| parser.on "-k PORT", "--kill-port=PORT", "Kill process on port" do |port|
ltnp_operator = CommandRunner.run_ltnp ltnp_operator = CommandRunner.run_ltnp
record = ltnp_operator.get_port_record port record = ltnp_operator.get_port_record port
unless record.nil? unless record.nil?
puts "Port: %s, Process: %s, Process ID: %s" % [record.port, record.p_name, record.pid] puts record.out_s
puts "Would you like to kill %s? (y/n)" % [record.p_name] puts "Would you like to kill %s? (y/n)" % [record.p_name]
input = gets input = gets
unless input.nil? unless input.nil?

@ -16,4 +16,17 @@ describe LtnpOperator do
sut.get_port_record(nonsense_port).nil?.should be_true sut.get_port_record(nonsense_port).nil?.should be_true
end end
end end
describe "#search_p_name" do
existing_p_name = "polymer"
nonsense_p_name = "thisisnotathing"
it "should find record when process exists" do
sut.search_p_name(existing_p_name).nil?.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
end
end
end end

Loading…
Cancel
Save