mirror of
https://github.com/johnkerl/miller.git
synced 2026-07-17 16:38:54 +00:00
* 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
46 lines
984 B
Go
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)
|
|
}
|