func Shell(call []string) error { var in *common.BufferedReader interactive := true if len(call) > 2 { call = call[0:1] } if len(call) == 2 { f, e := os.Open(call[1]) if e != nil { return e } defer f.Close() in = common.NewBufferedReader(f) interactive = false } else { in = common.NewBufferedReader(os.Stdin) } var e error var line string for e == nil { if interactive { fmt.Print("> ") } line, e = in.ReadWholeLine() if e != nil { return e } 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 }