mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-05 03:17:50 +08:00
pkg/eval: De-export PwdVariable.
This commit is contained in:
parent
948432e766
commit
a88ac31b39
|
@ -90,7 +90,6 @@ var builtinNs = Ns{
|
|||
"true": vars.NewReadOnly(true),
|
||||
"false": vars.NewReadOnly(false),
|
||||
"paths": NewEnvListVar("PATH"),
|
||||
"pwd": PwdVariable{},
|
||||
"args": vars.NewReadOnly(vector.Empty),
|
||||
}
|
||||
|
||||
|
|
|
@ -172,7 +172,7 @@ func NewEvaler() *Evaler {
|
|||
builtin["num-bg-jobs"] = vars.FromGet(func() interface{} {
|
||||
return strconv.Itoa(ev.state.getNumBgJobs())
|
||||
})
|
||||
builtin["pwd"] = PwdVariable{ev}
|
||||
builtin["pwd"] = NewPwdVar(ev)
|
||||
|
||||
return ev
|
||||
}
|
||||
|
|
|
@ -6,20 +6,24 @@ import (
|
|||
"github.com/elves/elvish/pkg/eval/vars"
|
||||
)
|
||||
|
||||
// PwdVariable is a variable whose value always reflects the current working
|
||||
// NewPwdVar returns a variable who value is synchronized with the path of the
|
||||
// current working directory.
|
||||
func NewPwdVar(ev *Evaler) vars.Var { return pwdVar{ev} }
|
||||
|
||||
// pwdVar is a variable whose value always reflects the current working
|
||||
// directory. Setting it changes the current working directory.
|
||||
type PwdVariable struct {
|
||||
type pwdVar struct {
|
||||
ev *Evaler
|
||||
}
|
||||
|
||||
var _ vars.Var = PwdVariable{}
|
||||
var _ vars.Var = pwdVar{}
|
||||
|
||||
// Getwd allows for unit test error injection.
|
||||
var getwd func() (string, error) = os.Getwd
|
||||
|
||||
// Get returns the current working directory. It returns "/unknown/pwd" when
|
||||
// it cannot be determined.
|
||||
func (PwdVariable) Get() interface{} {
|
||||
func (pwdVar) Get() interface{} {
|
||||
pwd, err := getwd()
|
||||
if err != nil {
|
||||
return "/unknown/pwd"
|
||||
|
@ -28,7 +32,7 @@ func (PwdVariable) Get() interface{} {
|
|||
}
|
||||
|
||||
// Set changes the current working directory.
|
||||
func (pwd PwdVariable) Set(v interface{}) error {
|
||||
func (pwd pwdVar) Set(v interface{}) error {
|
||||
path, ok := v.(string)
|
||||
if !ok {
|
||||
return ErrPathMustBeString
|
||||
|
|
Loading…
Reference in New Issue
Block a user