示例#1
0
文件: renderer.go 项目: sinzui/utils
// NewRenderer returns a Renderer for the given shell, OS, or distro name.
func NewRenderer(name string) (Renderer, error) {
	if name == "" {
		name = runtime.GOOS
	} else {
		name = strings.ToLower(name)
	}

	// Try known shell names first.
	switch name {
	case "bash":
		return &BashRenderer{}, nil
	case "ps", "powershell":
		return &PowershellRenderer{}, nil
	case "cmd", "batch", "bat":
		return &WinCmdRenderer{}, nil
	}

	// Fall back to operating systems.
	switch {
	case name == "windows":
		return &PowershellRenderer{}, nil
	case utils.OSIsUnix(name):
		return &BashRenderer{}, nil
	}

	// Finally try distros.
	switch name {
	case "ubuntu":
		return &BashRenderer{}, nil
	}

	return nil, errors.NotFoundf("renderer for %q", name)
}
示例#2
0
文件: os_test.go 项目: kat-co/utils
func (osSuite) TestOSIsUnixKnown(c *gc.C) {
	for _, os := range utils.OSUnix {
		c.Logf("checking %q", os)
		isUnix := utils.OSIsUnix(os)

		c.Check(isUnix, jc.IsTrue)
	}
}
示例#3
0
文件: filepath.go 项目: juju/utils
// NewRenderer returns a Renderer for the given os.
func NewRenderer(os string) (Renderer, error) {
	if os == "" {
		os = runtime.GOOS
	}

	os = strings.ToLower(os)
	switch {
	case os == utils.OSWindows:
		return &WindowsRenderer{}, nil
	case utils.OSIsUnix(os):
		return &UnixRenderer{}, nil
	case os == "ubuntu":
		return &UnixRenderer{}, nil
	default:
		return nil, errors.NotFoundf("renderer for %q", os)
	}
}
示例#4
0
文件: os_test.go 项目: kat-co/utils
func (osSuite) TestOSIsUnixUnknown(c *gc.C) {
	isUnix := utils.OSIsUnix("<unknown OS>")

	c.Check(isUnix, jc.IsFalse)
}
示例#5
0
文件: os_test.go 项目: kat-co/utils
func (osSuite) TestOSIsUnixWindows(c *gc.C) {
	isUnix := utils.OSIsUnix("windows")

	c.Check(isUnix, jc.IsFalse)
}