mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-05 03:17:50 +08:00
pkg/eval/vals: Replace MakeListFromStrings with a generic MakeListSlice.
This commit is contained in:
parent
01756ef57a
commit
d48b6f1843
|
@ -182,9 +182,9 @@ type closureFields struct{ c *Closure }
|
||||||
|
|
||||||
func (closureFields) IsStructMap() {}
|
func (closureFields) IsStructMap() {}
|
||||||
|
|
||||||
func (cf closureFields) ArgNames() vals.List { return vals.MakeListFromStrings(cf.c.ArgNames...) }
|
func (cf closureFields) ArgNames() vals.List { return vals.MakeListSlice(cf.c.ArgNames) }
|
||||||
func (cf closureFields) RestArg() string { return strconv.Itoa(cf.c.RestArg) }
|
func (cf closureFields) RestArg() string { return strconv.Itoa(cf.c.RestArg) }
|
||||||
func (cf closureFields) OptNames() vals.List { return vals.MakeListFromStrings(cf.c.OptNames...) }
|
func (cf closureFields) OptNames() vals.List { return vals.MakeListSlice(cf.c.OptNames) }
|
||||||
func (cf closureFields) Src() parse.Source { return cf.c.SrcMeta }
|
func (cf closureFields) Src() parse.Source { return cf.c.SrcMeta }
|
||||||
|
|
||||||
func (cf closureFields) OptDefaults() vals.List {
|
func (cf closureFields) OptDefaults() vals.List {
|
||||||
|
|
|
@ -284,7 +284,7 @@ func (ev *Evaler) addNumBgJobs(delta int) {
|
||||||
// the given slice. This method must be called before the Evaler is used to
|
// the given slice. This method must be called before the Evaler is used to
|
||||||
// evaluate any code.
|
// evaluate any code.
|
||||||
func (ev *Evaler) SetArgs(args []string) {
|
func (ev *Evaler) SetArgs(args []string) {
|
||||||
ev.Args = vals.MakeListFromStrings(args...)
|
ev.Args = vals.MakeListSlice(args)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddBeforeChdir adds a function to run before changing directory. This method
|
// AddBeforeChdir adds a function to run before changing directory. This method
|
||||||
|
|
|
@ -18,6 +18,11 @@ var EmptyList = vector.Empty
|
||||||
|
|
||||||
// MakeList creates a new List from values.
|
// MakeList creates a new List from values.
|
||||||
func MakeList(vs ...any) vector.Vector {
|
func MakeList(vs ...any) vector.Vector {
|
||||||
|
return MakeListSlice(vs)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MakeListSlice creates a new List from a slice.
|
||||||
|
func MakeListSlice[T any](vs []T) vector.Vector {
|
||||||
vec := vector.Empty
|
vec := vector.Empty
|
||||||
for _, v := range vs {
|
for _, v := range vs {
|
||||||
vec = vec.Conj(v)
|
vec = vec.Conj(v)
|
||||||
|
@ -25,15 +30,6 @@ func MakeList(vs ...any) vector.Vector {
|
||||||
return vec
|
return vec
|
||||||
}
|
}
|
||||||
|
|
||||||
// MakeListFromStrings creates a new List from strings.
|
|
||||||
func MakeListFromStrings(ss ...string) vector.Vector {
|
|
||||||
vec := vector.Empty
|
|
||||||
for _, s := range ss {
|
|
||||||
vec = vec.Conj(s)
|
|
||||||
}
|
|
||||||
return vec
|
|
||||||
}
|
|
||||||
|
|
||||||
// Map is an alias for the underlying type used for maps in Elvish.
|
// Map is an alias for the underlying type used for maps in Elvish.
|
||||||
type Map = hashmap.Map
|
type Map = hashmap.Map
|
||||||
|
|
||||||
|
|
|
@ -174,7 +174,7 @@ func parse(argsVal vals.List, specsVal vals.List) (vals.Map, vals.List, error) {
|
||||||
fs.VisitAll(func(f *flag.Flag) {
|
fs.VisitAll(func(f *flag.Flag) {
|
||||||
m = m.Assoc(f.Name, f.Value.(flag.Getter).Get())
|
m = m.Assoc(f.Name, f.Value.(flag.Getter).Get())
|
||||||
})
|
})
|
||||||
return m, vals.MakeListFromStrings(fs.Args()...), nil
|
return m, vals.MakeListSlice(fs.Args()), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func newFlagSet(name string) *flag.FlagSet {
|
func newFlagSet(name string) *flag.FlagSet {
|
||||||
|
@ -213,7 +213,7 @@ func (lf *listFlag) String() string { return vals.ToString(lf.value) }
|
||||||
func (lf *listFlag) Get() any { return lf.value }
|
func (lf *listFlag) Get() any { return lf.value }
|
||||||
|
|
||||||
func (lf *listFlag) Set(s string) error {
|
func (lf *listFlag) Set(s string) error {
|
||||||
lf.value = vals.MakeListFromStrings(strings.Split(s, ",")...)
|
lf.value = vals.MakeListSlice(strings.Split(s, ","))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -374,5 +374,5 @@ func parseGetopt(opts parseGetoptOptions, argsVal vals.List, specsVal vals.List)
|
||||||
"long", flag.Long))
|
"long", flag.Long))
|
||||||
}
|
}
|
||||||
|
|
||||||
return flagsList, vals.MakeListFromStrings(nonFlagArgs...), nil
|
return flagsList, vals.MakeListSlice(nonFlagArgs), nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user