當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。