Translator from shell to V scripts
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
756 B

module main
// Translates the shell script (lines as array) to a vsh script (lines as
// array)
fn translate(sh []string) []string {
mut vsh := []string{}
for line in sh {
// First line
if line.starts_with('#!/') {
vsh << '#!/usr/bin/env -S v run'
continue
}
// Empty lines
if line.strip_margin() == '' {
vsh << ''
continue
}
// Native chmod
if line.strip_margin().starts_with('chmod ') {
args := line.strip_margin().split(' ')
vsh << "chmod('${args[2]}', ${args[1]})"
continue
}
// Native println
if line.strip_margin().starts_with('echo ') {
args := line.strip_margin().split(' ')
print := args[1..].join(' ')
vsh << "println('${print}')"
continue
}
vsh << "system('$line')"
}
return vsh
}