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


Golang sh.Command類代碼示例

本文整理匯總了Golang中github.com/lotreal/docker-pods/src/sh.Command的典型用法代碼示例。如果您正苦於以下問題:Golang Command類的具體用法?Golang Command怎麽用?Golang Command使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: TestFoo

func TestFoo(t *testing.T) {
	cmd := sh.Command{"foo"}
	_, err := cmd.Run()
	if err.Error() != "exit status 127" {
		t.Errorf("command(%s) should exit with 127, but is: %#v", cmd.Text(), err.Error())
	}
}
開發者ID:lotreal,項目名稱:docker-pods,代碼行數:7,代碼來源:command_test.go

示例2: TestRun

func TestRun(t *testing.T) {
	cmd := sh.Command{"echo -n 12; echo 34"}
	out, _ := cmd.Run()
	if out != "1234" {
		t.Errorf("command(%s) should output 1234, but is: %#v", cmd.Text(), out)
	}
}
開發者ID:lotreal,項目名稱:docker-pods,代碼行數:7,代碼來源:command_test.go

示例3: RunPods

func RunPods(file string) (RunOutput, error) {
	var out RunOutput
	p, err := config.Pods(file)
	if err != nil {
		return out, err
	}

	script, err := MakeCmd(p)
	if err != nil {
		return out, err
	}

	cmd := sh.Command{script}
	fmt.Println(file)
	fmt.Println(script)
	fmt.Println("=============================")
	out = RunOutput{
		Pid:         p.Id,
		Pods:        file,
		ContainerId: cmd.Ok(),
		// ContainerId: cmd.Mock()[0],
	}

	return out, nil
}
開發者ID:lotreal,項目名稱:docker-pods,代碼行數:25,代碼來源:run.go

示例4: TestLines

func TestLines(t *testing.T) {
	cmd := sh.Command{"echo 12; echo 34"}
	out, _ := cmd.Lines()
	if len(out) != 2 {
		t.Errorf("command(%s) should output 2 line, but is: %#v", cmd.Text(), out)
	}
}
開發者ID:lotreal,項目名稱:docker-pods,代碼行數:7,代碼來源:command_test.go

示例5: gitDescribe

func gitDescribe(dir string) (string, error) {
	os.Chdir(dir)
	script := "git describe"
	cmd := sh.Command{script}

	out, err := cmd.Run()
	return out, err
}
開發者ID:lotreal,項目名稱:docker-pods,代碼行數:8,代碼來源:describe.go

示例6: InspectRunning

func InspectRunning(cid string) string {
	script := fmt.Sprintf("docker inspect --format='{{.State.Running}}' %s", cid)
	cmd := sh.Command{script}
	ret := cmd.Ok()
	if ret == "true" {
		return "YES"
	}
	return "NO"
}
開發者ID:lotreal,項目名稱:docker-pods,代碼行數:9,代碼來源:inspect.go

示例7: InspectPid

func InspectPid(cid string) string {
	script := fmt.Sprintf("docker inspect --format='{{.Config.Labels.name}}' %s", cid)
	cmd := sh.Command{script}
	ret := cmd.Ok()
	if ret == "<no value>" {
		return ""
	}
	return ret
}
開發者ID:lotreal,項目名稱:docker-pods,代碼行數:9,代碼來源:inspect.go

示例8: gitRev

func gitRev(dir string) (string, error) {
	os.Chdir(dir)

	script := "git rev-list --count --first-parent HEAD"
	cmd := sh.Command{script}
	out, err := cmd.Run()

	if err != nil {
		return "", err
	}

	return fmt.Sprintf("r%s", out), err
}
開發者ID:lotreal,項目名稱:docker-pods,代碼行數:13,代碼來源:describe.go

示例9: Ps

func Ps() []PsOutput {
	cmd := sh.Command{"docker ps -a"}

	lines, _ := cmd.Lines()
	var reader = sh.NewReader(lines, PsOutput{})

	var status []PsOutput
	status = make([]PsOutput, 0)

	for {
		var s PsOutput
		err := sh.Unmarshal(reader, &s)

		if err == io.EOF {
			break
		}
		if err != nil {
			panic(err)
		}
		status = append(status, s)
	}
	return status
}
開發者ID:lotreal,項目名稱:docker-pods,代碼行數:23,代碼來源:ps.go

示例10: TestRm

func TestRm(t *testing.T) {
	script := fmt.Sprintf("docker rm -f %s", busybox)
	cmd := sh.Command{script}
	t.Log(cmd.Ok())
}
開發者ID:lotreal,項目名稱:docker-pods,代碼行數:5,代碼來源:inspect_test.go

示例11: TestInit

package docker_test

import (
	"fmt"
	"testing"

	"github.com/lotreal/docker-pods/src/docker"
	"github.com/lotreal/docker-pods/src/sh"
)

var busybox = (func() string {
	cmd := sh.Command{"docker run -d -it busybox sh"}
	return cmd.Ok()[0:12]
})()

func TestInit(t *testing.T) {
	t.Logf("%s", docker.Ps())
	t.Logf("%s", busybox)
}

func TestIp(t *testing.T) {
	t.Log(docker.InspectIp(busybox))
}

func TestPort(t *testing.T) {
	t.Log(docker.InspectPorts(busybox))
}

func TestState(t *testing.T) {
	t.Log(docker.InspectPorts(busybox))
}
開發者ID:lotreal,項目名稱:docker-pods,代碼行數:31,代碼來源:inspect_test.go

示例12: InspectIp

func InspectIp(cid string) string {
	script := fmt.Sprintf("docker inspect --format='{{.NetworkSettings.IPAddress}}' %s", cid)
	cmd := sh.Command{script}
	return cmd.Ok()
}
開發者ID:lotreal,項目名稱:docker-pods,代碼行數:5,代碼來源:inspect.go

示例13: InspectPorts

func InspectPorts(cid string) string {
	script := fmt.Sprintf("docker inspect --format='{{range $p, $conf := .NetworkSettings.Ports}} {{$p}} -> {{(index $conf 0).HostPort}} {{end}}' %s", cid)
	cmd := sh.Command{script}
	ret := cmd.Ok()
	return ret
}
開發者ID:lotreal,項目名稱:docker-pods,代碼行數:6,代碼來源:inspect.go


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