当前位置: 首页>>代码示例>>Golang>>正文


Golang app.New函数代码示例

本文整理汇总了Golang中clive/app.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了New函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: 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

示例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: 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

示例4: main

func main() {
	defer app.Exiting()
	app.New()
	app.Close(0)
	ql.Run()
	app.Exits(nil)
}
开发者ID:Christopheraburns,项目名称:clive,代码行数:7,代码来源:ql.go

示例5: main

func main() {
	defer app.Exiting()
	app.New()
	app.SetIO(app.OSIn(), 0)
	xp.Run()
	app.Exits(nil)
}
开发者ID:Christopheraburns,项目名称:clive,代码行数:7,代码来源:xp.go

示例6: 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

示例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: 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

示例9: 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

示例10: 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

示例11: 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

示例12: 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

示例13: 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

示例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: TestLoad

func TestLoad(t *testing.T) {
	BibTexOk = false
	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("plan", "9", "networks")
	for _, r := range refs {
		app.Dprintf("got:\n%s\n", strings.Join(r.Reference(), "\n"))
	}
	if len(refs) != 2 {
		t.Fatalf("wrong count for plan 9 networks at lsub bib")
	}
}
开发者ID:Christopheraburns,项目名称:clive,代码行数:22,代码来源:refs_test.go


注:本文中的clive/app.New函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。