當前位置: 首頁>>代碼示例>>Golang>>正文


Golang app.Exiting函數代碼示例

本文整理匯總了Golang中clive/app.Exiting函數的典型用法代碼示例。如果您正苦於以下問題:Golang Exiting函數的具體用法?Golang Exiting怎麽用?Golang Exiting使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Exiting函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestCmds

func TestCmds(t *testing.T) {
	os.Args[0] = "ql.test"
	app.Debug = testing.Verbose() && false
	app.Verb = testing.Verbose() && false
	app.New()
	app.AppCtx().Debug = testing.Verbose()
	dbg.ExitDumpsStacks = testing.Verbose()
	defer app.Exiting()
	inc := make(chan interface{}, 3)
	inc <- []byte("hi\n")
	inc <- []byte("there\n")
	close(inc)
	app.SetIO(inc, 0)
	ql := func() {
		app.AppCtx().Debug = testing.Verbose()
		Run()
	}
	for _, c := range cmds {
		args := []string{"ql", "-c", c}
		if testing.Verbose() {
			args = []string{"ql", "-X", "-c", c}
		}
		x := app.Go(ql, args...)
		<-x.Wait
		if x.Sts != nil {
			t.Logf("did fail with sts %v", x.Sts)
		}
	}
}
開發者ID:Christopheraburns,項目名稱:clive,代碼行數:29,代碼來源:ql_test.go

示例2: TestParseStdin

func TestParseStdin(t *testing.T) {
	r, w, err := os.Pipe()
	if err != nil {
		t.Fatalf("pipe: %s", err)
	}
	fd, err := os.Open("example")
	if err != nil {
		t.Fatalf("ex: %s", err)
	}
	defer fd.Close()
	go func() {
		io.Copy(w, fd)
		w.Close()
	}()
	os.Stdin = r
	app.New()
	defer app.Exiting()
	ql := func() {
		c := app.AppCtx()
		c.Debug = testing.Verbose()
		app.SetIO(app.OSIn(), 0)
		Run()
	}
	x := app.Go(ql, "ql", "-n")
	<-x.Wait
	if x.Sts != nil {
		t.Fatalf("did fail")
	}
}
開發者ID:Christopheraburns,項目名稱:clive,代碼行數:29,代碼來源:ql_test.go

示例3: main

func main() {
	defer app.Exiting()
	app.New()
	app.Close(0)
	ql.Run()
	app.Exits(nil)
}
開發者ID:Christopheraburns,項目名稱:clive,代碼行數:7,代碼來源:ql.go

示例4: main

func main() {
	defer app.Exiting()
	app.New()
	app.SetIO(app.OSIn(), 0)
	xp.Run()
	app.Exits(nil)
}
開發者ID:Christopheraburns,項目名稱:clive,代碼行數:7,代碼來源:xp.go

示例5: main

func main() {
	os.Stdin.Close()
	defer app.Exiting()
	app.New()
	app.Close(0)
	wr.Run()
	app.Exits(nil)
}
開發者ID:Christopheraburns,項目名稱:clive,代碼行數:8,代碼來源:wr.go

示例6: TestFrmt

func TestFrmt(t *testing.T) {
	app.New() // prevent app.Fatal from calling dbg.Fatal
	//app.Debug = testing.Verbose()
	// gf
	pipe := make(chan interface{}, 2)
	pipe <- zx.Dir{"upath": "foo", "path": "foo"}
	pipe <- []byte(testpar)
	close(pipe)
	out := make(chan interface{})
	/*
		go func() {
			c := app.New()
			defer app.Exiting()
			c.Args = []string {"gf", "frmt,"}
			app.DupIO()
			app.SetIO(pipe, 1)
			app.Cd("/zx/sys/src/clive/app")
			lf.Run()
		}()
	*/

	// frmt
	go func() {
		c := app.New()
		//c.Debug = testing.Verbose()
		defer app.Exiting()
		c.Args = []string{"frmt", "-w", "50", "-r"}
		app.DupIO()
		app.SetIO(pipe, 0)
		app.SetIO(out, 1)
		app.Cd("/zx/sys/src/clive/app")
		Run()
	}()
	outs := ""
	for x := range out {
		switch x := x.(type) {
		case zx.Dir:
			dprintf("xgot %T %s\n", x, x["upath"])
		case []byte:
			if len(x) > 0 {
				x = x[:len(x)-1]
			}
			dprintf("[%s]\n", x)
			outs += string(x) + "\n"
		case error:
			dprintf("xgot %T %v\n", x, x)
		default:
			dprintf("xgot %T %v\n", x, x)
		}
	}
	dprintf("outs = `%s`\n", outs)
	err := cerror(out)
	dprintf("got sts %v\n", err)
	if outs != testout {
		t.Fatalf("bad output")
	}
}
開發者ID:Christopheraburns,項目名稱:clive,代碼行數:57,代碼來源:frmt_test.go

示例7: TestBib2ref

func TestBib2ref(t *testing.T) {
	c := app.New()
	defer app.Exiting()
	c.Debug = testing.Verbose()
	lnc := nsutil.GetLines("/zx/lib/bib/zx.bib")
	rc := bib2ref(lnc)
	for ln := range rc {
		app.Dprintf("%s", ln)
	}
}
開發者ID:Christopheraburns,項目名稱:clive,代碼行數:10,代碼來源:refs_test.go

示例8: TestParseError

func TestParseError(t *testing.T) {
	app.New()
	defer app.Exiting()
	ql := func() {
		app.AppCtx().Debug = testing.Verbose()
		Run()
	}
	x := app.Go(ql, "ql", "-n", "-c", "pw{d")
	<-x.Wait
	if x.Sts == nil {
		t.Logf("warn: ql didn't fail")
	}
}
開發者ID:Christopheraburns,項目名稱:clive,代碼行數:13,代碼來源:ql_test.go

示例9: TestParseCmd

func TestParseCmd(t *testing.T) {
	app.New()
	defer app.Exiting()
	ql := func() {
		app.AppCtx().Debug = testing.Verbose()
		Run()
	}
	x := app.Go(ql, "ql", "-n", "-c", "pwd")
	<-x.Wait
	if x.Sts != nil {
		t.Fatalf("did fail")
	}
}
開發者ID:Christopheraburns,項目名稱:clive,代碼行數:13,代碼來源:ql_test.go

示例10: main

func main() {
	defer app.Exiting()
	x := app.New()
	stacks := false
	opts.NewFlag("F", "debug fuse requests", &zxfs.Debug)
	opts.NewFlag("D", "debug", &x.Debug)
	opts.NewFlag("s", "statistics", &sflag)
	opts.NewFlag("x", "addr: re-export locally the ql tree to this address", &xaddr)
	opts.NewFlag("S", "dump stacks on unmount for debugging", &stacks)
	args, err := opts.Parse(x.Args)
	if err != nil {
		app.Warn("%s", err)
		opts.Usage()
		app.Exits(err)
	}
	switch len(args) {
	case 0:
	case 1:
		mntdir = args[1]
	default:
		app.Warn("wrong number of arguments")
		opts.Usage()
		app.Exits("usage")
	}
	dprintf("debug on\n")
	qfs, err := qlfs.New("qlfs")
	if err != nil {
		app.Fatal(err)
	}
	qfs.Dbg = x.Debug
	qfs.Flags.Add("fdebug", &zxfs.Debug)
	st := &zx.IOstats{}
	qfs.IOstats = st
	if xaddr != "" {
		rfs.Server(qfs, xaddr)
	}
	err = zxfs.MountServer(qfs, mntdir)
	if sflag {
		st.Averages()
		app.Warn("%s iostats:\n%s\n", qfs.Name(), st)
	}
	if stacks {
		app.Warn("*** PANICING ON USER REQUEST (-S) ***")
		panic("stack dump")
	}
	if err != nil {
		app.Fatal("%s", err)
	}
	app.Warn("unmounted: exiting")
}
開發者ID:Christopheraburns,項目名稱:clive,代碼行數:50,代碼來源:qlfs.go

示例11: runType

func runType(x *xEnv, argv ...string) error {
	defer app.Exiting()
	opts := opt.New("{name}")
	app.Dprintf("type %v\n", argv)
	args, err := opts.Parse(argv)
	if err != nil {
		opts.Usage()
		app.Exits(dbg.ErrUsage)
	}
	for _, n := range args {
		app.Printf("%s: %s\n", n, x.ntype(n))
	}
	app.Exits(nil)
	return nil
}
開發者ID:Christopheraburns,項目名稱:clive,代碼行數:15,代碼來源:bltin.go

示例12: TestLf

func TestLf(t *testing.T) {
	app.New()	// prevent app.Fatal from calling dbg.Fatal
	app.Debug = testing.Verbose()
	for i := range tests {
		lt := tests[i]
		dprintf("run %v\n", lt.args)
		out := make(chan interface{})
		go func() {
			c := app.New()
			c.Args = lt.args
			defer app.Exiting()
			app.DupIO()
			app.SetIO(out, 1)
			app.Cd("/zx/sys/src/clive")
			Run()
		}()
		outs := []string{}
		for x := range out {
			d, ok := x.(zx.Dir)
			if !ok {
				dprintf("got %T %v\n", x, x)
				t.Fatalf("not a dir")
			}
			dprintf("got %T %s\n", d, d["upath"])
			outs = append(outs, d["upath"])
		}
		err := cerror(out)
		dprintf("got sts %v\n", err)
		if lt.fails && err == nil {
			t.Fatalf("didn't fail")
		}
		if !lt.fails && err != nil {
			t.Fatalf("failed: %s", err)
		}
		if lt.out != nil && strings.Join(lt.out, " ") != strings.Join(outs, " ") {
			t.Fatalf("bad output %#v", outs)
		}
		if lt.out == nil {
			dprintf("out: %#v\n", outs)
		}
	}
}
開發者ID:Christopheraburns,項目名稱:clive,代碼行數:42,代碼來源:lf_test.go

示例13: main

func main() {
	defer app.Exiting()
	os.Args[0] = "auth"
	app.New()
	dfltdir := auth.KeyDir()
	dir = dfltdir
	opts.NewFlag("d", "adir: clive auth dir", &dir)
	opts.NewFlag("f", "force write of key file when file already exists", &force)
	args, err := opts.Parse(os.Args)
	if err != nil {
		app.Warn("%s", err)
		opts.Usage()
		app.Exits(err)
	}
	if len(args) < 3 {
		opts.Usage()
		app.Exits("usage")
	}
	name, user, secret := args[0], args[1], args[2]
	groups := args[3:]
	file := auth.KeyFile(dir, name)
	fi, _ := os.Stat(file)
	if fi != nil && !force {
		app.Fatal("key file already exists")
	}
	err = auth.SaveKey(dir, name, user, secret, groups...)
	if err != nil {
		app.Fatal("%s: %s", file, err)
	}
	ks, err := auth.LoadKey(dir, name)
	if err != nil {
		app.Fatal("can't load key: %s", err)
	}
	for _, k := range ks {
		if k.Uid == user {
			app.Warn("%s", file)
			return
		}
	}
	app.Fatal("bad user")
}
開發者ID:Christopheraburns,項目名稱:clive,代碼行數:41,代碼來源:auth.go

示例14: main

func main() {
	defer app.Exiting()
	app.New()
	opts.NewFlag("p", "port: port used (8080 by default)", &port)
	args, err := opts.Parse(os.Args)
	if err != nil {
		app.Warn("%s", err)
		opts.Usage()
		app.Exits(err)
	}
	switch len(args) {
	case 0:
	case 1:
		dir = args[0]
	default:
		app.Warn("too many arguments")
		opts.Usage()
		app.Exits("usage")
	}
	err = http.ListenAndServe(":"+port, http.FileServer(http.Dir(dir)))
	app.Exits(err)
}
開發者ID:Christopheraburns,項目名稱:clive,代碼行數:22,代碼來源:web.go

示例15: TestBibLoad

func TestBibLoad(t *testing.T) {
	BibTexOk = true
	c := app.New()
	defer app.Exiting()
	c.Debug = testing.Verbose()
	b, err := Load("/zx/lib/bib")
	if err != nil {
		t.Fatalf("load: %s", err)
	}
	if testing.Verbose() {
		b.WriteTo(os.Stdout)
	}

	app.Dprintf("cite plan 9 networks:\n")
	refs := b.Cites("VisageFS")
	for _, r := range refs {
		app.Dprintf("got:\n%s\n", strings.Join(r.Reference(), "\n"))
	}
	if len(refs) == 0 {
		t.Fatalf("did not find visage in bib")
	}
}
開發者ID:Christopheraburns,項目名稱:clive,代碼行數:22,代碼來源:refs_test.go


注:本文中的clive/app.Exiting函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。