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


Golang pipe.Line函数代码示例

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


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

示例1: TestLineIsolatesEnv

func (S) TestLineIsolatesEnv(c *C) {
	p := pipe.Line(
		pipe.SetEnvVar("PIPE_VAR", "outer"),
		pipe.Line(
			pipe.SetEnvVar("PIPE_VAR", "inner"),
		),
		pipe.System("echo $PIPE_VAR"),
	)
	output, err := pipe.Output(p)
	c.Assert(err, IsNil)
	c.Assert(string(output), Equals, "outer\n")
}
开发者ID:javouhey,项目名称:seneca,代码行数:12,代码来源:pipe_test.go

示例2: TestLineNesting

func (S) TestLineNesting(c *C) {
	b := &bytes.Buffer{}
	p := pipe.Line(
		pipe.Print("hello"),
		pipe.Line(
			pipe.Filter(func(line []byte) bool { return true }),
			pipe.Exec("sed", "s/l/k/g"),
		),
		pipe.Write(b),
	)
	err := pipe.Run(p)
	c.Assert(err, IsNil)
	c.Assert(b.String(), Equals, "hekko")
}
开发者ID:javouhey,项目名称:seneca,代码行数:14,代码来源:pipe_test.go

示例3: TestLineIsolatesDir

func (S) TestLineIsolatesDir(c *C) {
	dir1 := c.MkDir()
	dir2 := c.MkDir()
	p := pipe.Line(
		pipe.ChDir(dir1),
		pipe.Line(
			pipe.ChDir(dir2),
		),
		pipe.System("echo $PWD"),
	)
	output, err := pipe.Output(p)
	c.Assert(err, IsNil)
	c.Assert(string(output), Equals, dir1+"\n")
}
开发者ID:javouhey,项目名称:seneca,代码行数:14,代码来源:pipe_test.go

示例4: Pipe

// Pipe connects the output of one Executable to the input of the next
// Executable in the list.  The result is an Executable that, when run, returns
// the output of the last Executable run, and any error it might have had.
//
// If any of the Executables fails, no further Executables are run, and the
// failing Executable's stderr and error are returned.
func Pipe(cmds ...Executable) Executable {
	ps := make([]pipe.Pipe, len(cmds))
	for i, c := range cmds {
		ps[i] = c.Pipe
	}
	return Executable{pipe.Line(ps...)}
}
开发者ID:simudream,项目名称:sh-2,代码行数:13,代码来源:sh.go

示例5: PipeWith

// PipeWith functions like Pipe, but runs the first command with stdin as the
// input.
func PipeWith(stdin string, cmds ...Executable) Executable {
	ps := make([]pipe.Pipe, len(cmds)+1)
	ps[0] = pipe.Read(strings.NewReader(stdin))
	for i, c := range cmds {
		ps[i+1] = c.Pipe
	}
	return Executable{pipe.Line(ps...)}
}
开发者ID:simudream,项目名称:sh-2,代码行数:10,代码来源:sh.go

示例6: TestFilter

func (S) TestFilter(c *C) {
	p := pipe.Line(
		pipe.System("echo out1; echo err1 1>&2; echo out2; echo err2 1>&2; echo out3"),
		pipe.Filter(func(line []byte) bool { return string(line) != "out2" }),
	)
	output, err := pipe.Output(p)
	c.Assert(err, IsNil)
	c.Assert(string(output), Equals, "out1\nout3\n")
}
开发者ID:javouhey,项目名称:seneca,代码行数:9,代码来源:pipe_test.go

示例7: TestRead

func (S) TestRead(c *C) {
	p := pipe.Line(
		pipe.Read(bytes.NewBufferString("hello")),
		pipe.Exec("sed", "s/l/k/g"),
	)
	output, err := pipe.Output(p)
	c.Assert(err, IsNil)
	c.Assert(string(output), Equals, "hekko")
}
开发者ID:javouhey,项目名称:seneca,代码行数:9,代码来源:pipe_test.go

示例8: TestPrintf

func (S) TestPrintf(c *C) {
	p := pipe.Line(
		pipe.Printf("hello:%d", 42),
		pipe.Exec("sed", "s/l/k/g"),
	)
	output, err := pipe.Output(p)
	c.Assert(err, IsNil)
	c.Assert(string(output), Equals, "hekko:42")
}
开发者ID:javouhey,项目名称:seneca,代码行数:9,代码来源:pipe_test.go

示例9: TestFilterNoNewLine

func (S) TestFilterNoNewLine(c *C) {
	p := pipe.Line(
		pipe.Print("out1\nout2\nout3"),
		pipe.Filter(func(line []byte) bool { return string(line) != "out2" }),
	)
	output, err := pipe.Output(p)
	c.Assert(err, IsNil)
	c.Assert(string(output), Equals, "out1\nout3")
}
开发者ID:javouhey,项目名称:seneca,代码行数:9,代码来源:pipe_test.go

示例10: TestLine

func (S) TestLine(c *C) {
	p := pipe.Line(
		pipe.Exec("/bin/sh", "-c", "echo out1; echo err1 1>&2; echo out2; echo err2 1>&2"),
		pipe.Exec("sed", `s/\(...\)\([12]\)/\1-\2/`),
	)
	output, err := pipe.CombinedOutput(p)
	c.Assert(err, IsNil)
	c.Assert(string(output), Equals, "err1\nerr2\nout-1\nout-2\n")
}
开发者ID:javouhey,项目名称:seneca,代码行数:9,代码来源:pipe_test.go

示例11: TestReadFileNonExistent

func (S) TestReadFileNonExistent(c *C) {
	path := filepath.Join(c.MkDir(), "file")
	p := pipe.Line(
		pipe.ReadFile(path),
		pipe.Exec("cat"),
	)
	output, err := pipe.Output(p)
	c.Assert(err, ErrorMatches, "open .*/file: no such file or directory")
	c.Assert(output, IsNil)
}
开发者ID:javouhey,项目名称:seneca,代码行数:10,代码来源:pipe_test.go

示例12: TestDiscard

func (S) TestDiscard(c *C) {
	p := pipe.Line(
		pipe.Print("hello"),
		pipe.Discard(),
		pipe.Print("world"),
	)
	output, err := pipe.Output(p)
	c.Assert(err, IsNil)
	c.Assert(string(output), Equals, "world")
}
开发者ID:javouhey,项目名称:seneca,代码行数:10,代码来源:pipe_test.go

示例13: TestAppendFileAbsolute

func (S) TestAppendFileAbsolute(c *C) {
	path := filepath.Join(c.MkDir(), "file")
	p := pipe.Script(
		pipe.Line(
			pipe.Print("hello "),
			pipe.AppendFile(path, 0600),
		),
		pipe.Line(
			pipe.Print("world!"),
			pipe.AppendFile(path, 0600),
		),
	)
	output, err := pipe.Output(p)
	c.Assert(err, IsNil)
	c.Assert(string(output), Equals, "")

	data, err := ioutil.ReadFile(path)
	c.Assert(err, IsNil)
	c.Assert(string(data), Equals, "hello world!")
}
开发者ID:javouhey,项目名称:seneca,代码行数:20,代码来源:pipe_test.go

示例14: TestScriptPreservesStreams

func (S) TestScriptPreservesStreams(c *C) {
	p := pipe.Script(
		pipe.Line(
			pipe.Print("hello\n"),
			pipe.Discard(),
		),
		pipe.Exec("echo", "world"),
	)
	output, err := pipe.Output(p)
	c.Assert(err, IsNil)
	c.Assert(string(output), Equals, "world\n")
}
开发者ID:javouhey,项目名称:seneca,代码行数:12,代码来源:pipe_test.go

示例15: TestTee

func (S) TestTee(c *C) {
	var b bytes.Buffer
	p := pipe.Line(
		pipe.Print("hello"),
		pipe.Exec("sed", "s/l/k/g"),
		pipe.Tee(&b),
	)
	output, err := pipe.Output(p)
	c.Assert(err, IsNil)
	c.Assert(string(output), Equals, "hekko")
	c.Assert(b.String(), Equals, "hekko")
}
开发者ID:javouhey,项目名称:seneca,代码行数:12,代码来源:pipe_test.go


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