예제 #1
0
파일: serve_cli.go 프로젝트: e8vm/shanhu
func shellExec(h *Handler, c *context, id int64, dir, line string) (
	*shell.Results, error,
) {
	ch, err := openChanges(h, id)
	if err != nil {
		return nil, err
	}

	ro := changesReadOnly(h, c, ch)
	res := new(shell.Results)
	j := &shell.Job{
		Line: line,

		DB:       h.s.SiteDB,
		RepoDB:   h.s.RepoDB,
		Changes:  ch,
		ReadOnly: ro,
		IsAdmin:  c.userInfo.IsAdmin,
		User:     c.user,
		Cwd:      dir,

		Results: res,
	}

	if err := shell.Run(j); err != nil {
		return nil, err
	}
	return res, nil
}
예제 #2
0
파일: main.go 프로젝트: e8vm/shanhu
func exec(j *shell.Job) {
	set := new(shell.Results)
	j.Results = set

	if err := shell.Run(j); err != nil {
		fmt.Println(err)
	}

	for _, obj := range set.Objs {
		switch obj := obj.Obj.(type) {
		case string:
			fmt.Println(obj)
		case *shell.Error:
			fmt.Println("error: ", obj.Err)
		case *shell.ChangeDir:
			j.Cwd = obj.NewDir
		case *shell.OpenFile:
			fmt.Println("open file: ", obj.File)
		case *shell.PrintFile:
			fmt.Println(obj.Content)
		case *shell.BuildSnapshot:
			fmt.Println("build snapshot: ", obj.Hash)
			opt := &builds.Options{
				RunTests:   obj.RunTests,
				TestCycles: 1e6,
				Verbose:    true,
			}
			image, errs := obj.Snapshot.Build(obj.Pkgs, opt)
			if errs != nil {
				for _, err := range errs {
					fmt.Println(err)
				}
				return
			}
			if image == nil {
				return
			}

			fmt.Printf("(image size: %d bytes)\n", len(image))
			n, err := arch.RunImage(image, 100000)
			fmt.Printf("(%d cycles)\n", n)
			if !arch.IsHalt(err) {
				fmt.Println(err)
			}
		}
	}
}