func Shell(call []string) error { var in *common.BufferedReader interactive := true if len(call) > 2 { call = call[0:1] } if len(call) == 2 { f, err := os.Open(call[1]) if err != nil { return err } defer f.Close() in = common.NewBufferedReader(f) interactive = false } else { in = common.NewBufferedReader(os.Stdin) } var err error var line string for err == nil { if interactive { fmt.Print("> ") } line, err = in.ReadWholeLine() if err != nil { return err } if isComment(line) { continue } params, ce := common.Parameterize(line) if ce != nil { common.DumpError(ce) continue } ce = execute(params) if ce != nil { common.DumpError(ce) continue } } return nil }
func main() { defer func() { if p := recover(); p != nil { e, ok := p.(error) if !ok { e = errors.New("Some error occured") } common.DumpError(e) } }() run() }
func install(path string) error { goboxpath, e := common.GetGoboxBinaryPath() if e != nil { return e } for name := range Applets { // Don't overwrite the executable if name == "gobox" { continue } newpath := filepath.Join(path, name) e = common.ForcedSymlink(goboxpath, newpath) if e != nil { common.DumpError(e) } } return nil }
func startServer(addr string, call []string) error { ta, e := net.ResolveTCPAddr("tcp4", addr) if e != nil { return e } l, e := net.ListenTCP("tcp4", ta) if e != nil { return e } defer l.Close() for { c, e := l.Accept() if e == nil { } else { common.DumpError(e) } go serve(c, call) } return nil }