Skip to content
This repository was archived by the owner on Sep 6, 2024. It is now read-only.

Commit 80499ab

Browse files
committed
add more comments, and stop depending on system commands for hostname
1 parent 88df7be commit 80499ab

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/crfetch.cr

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ module Manip
66
MEBIBYTE = 1048576
77

88
def self.bytes_to_mebibytes(bytes : String) : String
9-
# Implement turning bytes into Mebibytes
109
bytes = bytes.strip.to_f / MEBIBYTE
1110

11+
# return with two decimal places
1212
"%.2f" % bytes
1313
end
1414
end
@@ -19,11 +19,12 @@ module Resource
1919
end
2020

2121
private def self.scrape_file(query : String, file : String) : String
22-
release_file = file
23-
`grep #{query} #{release_file}`
24-
.split('=', 2)
25-
.last
26-
.delete('"')
22+
File.each_line(file) do |line|
23+
if line.includes?(query)
24+
return line.split('=', 2)[1].delete('"').strip
25+
end
26+
end
27+
""
2728
end
2829

2930
def self.get_platform : String
@@ -57,7 +58,7 @@ module Resource
5758
end
5859

5960
def self.get_host : String
60-
`hostname`
61+
System.hostname
6162
end
6263

6364
def self.get_shell : String
@@ -110,6 +111,7 @@ module OptionHandler
110111
property separator = " -> "
111112
end
112113

114+
# inherit the Exception class
113115
class OptionError < Exception; end
114116

115117
def self.parse

0 commit comments

Comments
 (0)