// Eval evaluates the specified statement in the current namespace.
Eval evaluates the specified statement in the current namespace.
// Eval evaluates the specified statement in the current namespace .
func (g *Gosh) Eval(line string) {
	parts := strings.Split(line, " ")
	if len(parts) == 0 || parts[0] == "" {
		return
	}
	switch parts[0] {
	case "exit":
		g.WriteString("Goodbye.")
		g.Close()
	case "cd":
		var err error
		if len(parts) == 1 {
			home, _ := os.UserHomeDir() 
			err = g.changeWD(home)
		} else {
			err = g.changeWD(parts[1])
		}
		if err != nil {
			g.WriteString("Error: ")
			g.WriteString(err.Error())
			g.WriteString("\r\n")
		}
	case "gst":
		cmd := exec.Command("git", "status")
		inPipe, inErr := cmd.StdinPipe()
		outPipe, outErr := cmd.StdoutPipe()
		errPipe, errErr := cmd.StderrPipe()
		if inErr != nil || outErr != nil || errErr != nil {
			g.WriteString("Error running the command: \r\n")
			g.WriteString(inErr.Error() + "\r\n")
			g.WriteString(outErr.Error() + "\r\n")
			g.WriteString(errErr.Error() + "\r\n")
		}
		go io.Copy(inPipe, os.Stdin)
		go io.Copy(os.Stdout, outPipe)
		go io.Copy(os.Stdout, errPipe)
		cmd.Start()
		cmd.Wait()
	default:
		g.WriteString("Unknown command '")
		g.WriteString(line)
		g.WriteString("'")
		g.WriteString("\r\n")
	}
}
func ( g * Gosh ) Eval ( line string ) { parts := strings . Split ( line , " " ) if len ( parts ) == 0 || parts [ 0 ] == " " { return } switch parts [ 0 ] { case " " : g . WriteString ( " " ) g . Close ( ) case " " : var err error if len ( parts ) == 1 { home , _ := os . UserHomeDir ( ) err = g . changeWD ( home ) } else { err = g . changeWD ( parts [ 1 ] ) } if err != nil { g . WriteString ( " " ) g . WriteString ( err . Error ( ) ) g . WriteString ( " \r \n " ) } case " " : cmd := exec . Command ( " " , " " ) inPipe , inErr := cmd . StdinPipe ( ) outPipe , outErr := cmd . StdoutPipe ( ) errPipe , errErr := cmd . StderrPipe ( ) if inErr != nil || outErr != nil || errErr != nil { g . WriteString ( " \r \n " ) g . WriteString ( inErr . Error ( ) + " \r \n " ) g . WriteString ( outErr . Error ( ) + " \r \n " ) g . WriteString ( errErr . Error ( ) + " \r \n " ) } go io . Copy ( inPipe , os . Stdin ) go io . Copy ( os . Stdout , outPipe ) go io . Copy ( os . Stdout , errPipe ) cmd . Start ( ) cmd . Wait ( ) default : g . WriteString ( " " ) g . WriteString ( line ) g . WriteString ( " " ) g . WriteString ( " \r \n " ) } }
Eval evaluates the specified statement in the current namespace.
Eval evaluates the specified statement in the current namespace .
//nolint errcheck // This will get implemented later in conjunction with the parser