mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-05 03:17:50 +08:00
Add an experimental -ifaddrs builtin.
This commit is contained in:
parent
3c2df84afa
commit
410354b1df
|
@ -11,6 +11,7 @@ import (
|
|||
"io/ioutil"
|
||||
"math"
|
||||
"math/rand"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
|
@ -192,6 +193,8 @@ func init() {
|
|||
&BuiltinFn{"-stack", WrapFn(_stack)},
|
||||
&BuiltinFn{"-log", WrapFn(_log)},
|
||||
&BuiltinFn{"-time", WrapFn(_time)},
|
||||
|
||||
&BuiltinFn{"-ifaddrs", WrapFn(_ifaddrs)},
|
||||
}
|
||||
for _, b := range builtinFns {
|
||||
builtinNamespace[FnPrefix+b.Name] = NewRoVariable(b)
|
||||
|
@ -1135,6 +1138,16 @@ func _time(ec *EvalCtx, f FnValue) {
|
|||
fmt.Fprintln(ec.ports[1].File, dt)
|
||||
}
|
||||
|
||||
func _ifaddrs(ec *EvalCtx) {
|
||||
out := ec.ports[1].Chan
|
||||
|
||||
addrs, err := net.InterfaceAddrs()
|
||||
maybeThrow(err)
|
||||
for _, addr := range addrs {
|
||||
out <- String(addr.String())
|
||||
}
|
||||
}
|
||||
|
||||
func exec(ec *EvalCtx, args ...string) {
|
||||
if len(args) == 0 {
|
||||
args = []string{"elvish"}
|
||||
|
|
Loading…
Reference in New Issue
Block a user