Beispiel #1
0
// 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)
}
Beispiel #2
0
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)
	}
}
Beispiel #3
0
// 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)
	}
}
Beispiel #4
0
func (osSuite) TestOSIsUnixUnknown(c *gc.C) {
	isUnix := utils.OSIsUnix("<unknown OS>")

	c.Check(isUnix, jc.IsFalse)
}
Beispiel #5
0
func (osSuite) TestOSIsUnixWindows(c *gc.C) {
	isUnix := utils.OSIsUnix("windows")

	c.Check(isUnix, jc.IsFalse)
}