miller/internal/pkg/bifs/system.go
John Kerl 7a97c9b868
Performance improvement by JIT type inference (#786)
* JIT mlrval type-interfence: mlrval package

* mlrmap refactor

* complete merge from #779

* iterating

* mlrval/format.go

* mlrval/copy.go

* bifs/arithmetic_test.go

* iterate on bifs/collections_test.go

* mlrval_cmp.go

* mlrval JSON iterate

* iterate applying mlrval refactors to dependent packages

* first clean compile in a long while on this branch

* results of first post-compile profiling

* testing

* bugfix in ofmt formatting

* bugfix in octal-supporess

* go fmt

* neaten

* regression tests all passing
2021-12-20 23:56:04 -05:00

46 lines
984 B
Go

package bifs
import (
"os"
"os/exec"
"runtime"
"strings"
"github.com/johnkerl/miller/internal/pkg/mlrval"
"github.com/johnkerl/miller/internal/pkg/platform"
"github.com/johnkerl/miller/internal/pkg/version"
)
func BIF_version() *mlrval.Mlrval {
return mlrval.FromString(version.STRING)
}
func BIF_os() *mlrval.Mlrval {
return mlrval.FromString(runtime.GOOS)
}
func BIF_hostname() *mlrval.Mlrval {
hostname, err := os.Hostname()
if err != nil {
return mlrval.ERROR
} else {
return mlrval.FromString(hostname)
}
}
func BIF_system(input1 *mlrval.Mlrval) *mlrval.Mlrval {
if !input1.IsStringOrVoid() {
return mlrval.ERROR
}
commandString := input1.AcquireStringValue()
shellRunArray := platform.GetShellRunArray(commandString)
outputBytes, err := exec.Command(shellRunArray[0], shellRunArray[1:]...).Output()
if err != nil {
return mlrval.ERROR
}
outputString := strings.TrimRight(string(outputBytes), "\n")
return mlrval.FromString(outputString)
}