mirror of
https://github.com/vlang/v.git
synced 2025-09-15 15:32:27 +03:00
tools: simplify the implementation of get_linux_os_name in v doctor
This commit is contained in:
parent
0464ed792e
commit
eee32e52db
1 changed files with 13 additions and 37 deletions
|
@ -206,46 +206,22 @@ fn (app &App) parse(config string, sep string) map[string]string {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (mut a App) get_linux_os_name() string {
|
fn (mut a App) get_linux_os_name() string {
|
||||||
mut os_details := ''
|
if os.is_file('/etc/os-release') {
|
||||||
linux_os_methods := ['os-release', 'lsb_release', 'kernel', 'uname']
|
if lines := os.read_file('/etc/os-release') {
|
||||||
for m in linux_os_methods {
|
|
||||||
match m {
|
|
||||||
'os-release' {
|
|
||||||
if !os.is_file('/etc/os-release') {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
lines := os.read_file('/etc/os-release') or { continue }
|
|
||||||
vals := a.parse(lines, '=')
|
vals := a.parse(lines, '=')
|
||||||
if vals['PRETTY_NAME'] == '' {
|
if vals['PRETTY_NAME'] != '' {
|
||||||
continue
|
return vals['PRETTY_NAME']
|
||||||
}
|
}
|
||||||
os_details = vals['PRETTY_NAME']
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
'lsb_release' {
|
|
||||||
exists := a.cmd(command: 'type lsb_release')
|
|
||||||
if exists.starts_with('Error') {
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
os_details = a.cmd(command: 'lsb_release -d -s')
|
if !a.cmd(command: 'type lsb_release').starts_with('Error') {
|
||||||
break
|
return a.cmd(command: 'lsb_release -d -s')
|
||||||
}
|
}
|
||||||
'kernel' {
|
if os.is_file('/proc/version') {
|
||||||
if !os.is_file('/proc/version') {
|
return a.cmd(command: 'cat /proc/version')
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
os_details = a.cmd(command: 'cat /proc/version')
|
|
||||||
break
|
|
||||||
}
|
|
||||||
'uname' {
|
|
||||||
ouname := os.uname()
|
ouname := os.uname()
|
||||||
os_details = '${ouname.release}, ${ouname.version}'
|
return '${ouname.release}, ${ouname.version}'
|
||||||
break
|
|
||||||
}
|
|
||||||
else {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return os_details
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (mut a App) cpu_info(key string) string {
|
fn (mut a App) cpu_info(key string) string {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue