Documentation
¶
Overview ¶
Package platform provides cross-platform utilities for path handling, shell execution, and platform detection.
This package abstracts platform-specific differences between Unix systems (Linux, macOS, BSD) and Windows, allowing the build tool to work consistently across all supported platforms.
Shell Execution ¶
On Unix systems, the default shell is /bin/sh with the -c flag. On Windows, cmd.exe is used with the /C flag, or PowerShell with -Command.
Path Handling ¶
Paths are normalized to use forward slashes internally for consistency. The package detects absolute paths on both Unix (starting with /) and Windows (drive letter or UNC paths).
Shell Quoting ¶
Shell quoting differs between platforms:
- Unix shells use single quotes (')
- cmd.exe uses double quotes (")
- PowerShell uses single quotes (')
Index ¶
- func DefaultShell() string
- func IsAbsolutePath(path string) bool
- func IsDirectoryPath(path string) bool
- func IsWindows() bool
- func IsWindowsShell(shell string) bool
- func NormalizePath(path string) string
- func PathSeparator() byte
- func ShellCommandArgs(shell, command string) []string
- func ShellQuote(shell, value string) string
- func ValidateShell(shell string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultShell ¶
func DefaultShell() string
DefaultShell returns the default shell for the current platform. On Windows, returns cmd.exe. On Unix systems, returns /bin/sh.
func IsAbsolutePath ¶
IsAbsolutePath returns true if the path is an absolute path. This handles both Unix-style paths (/foo) and Windows-style paths (C:\foo, \\server\share).
func IsDirectoryPath ¶
IsDirectoryPath returns true if the path ends with a directory separator.
func IsWindowsShell ¶
IsWindowsShell returns true if the shell is a Windows shell (cmd.exe or PowerShell).
func NormalizePath ¶
NormalizePath converts all backslashes to forward slashes for consistency. This is useful for internal path representation.
func PathSeparator ¶
func PathSeparator() byte
PathSeparator returns the OS-specific path separator.
func ShellCommandArgs ¶
ShellCommandArgs returns the command-line arguments to pass a command to a shell. For Unix shells (sh, bash, zsh), this returns ["-c", command]. For cmd.exe, this returns ["/C", command]. For PowerShell, this returns ["-Command", command].
func ShellQuote ¶
ShellQuote quotes a string for safe use in shell commands. The quoting style depends on the shell:
- Unix shells: single quotes with escaped embedded single quotes
- cmd.exe: double quotes
- PowerShell: single quotes
func ValidateShell ¶
ValidateShell checks that the shell exists and is executable. Returns an error if the shell cannot be found.
Types ¶
This section is empty.