platform

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 22, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

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

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

func IsAbsolutePath(path string) bool

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

func IsDirectoryPath(path string) bool

IsDirectoryPath returns true if the path ends with a directory separator.

func IsWindows

func IsWindows() bool

IsWindows returns true if running on Windows.

func IsWindowsShell

func IsWindowsShell(shell string) bool

IsWindowsShell returns true if the shell is a Windows shell (cmd.exe or PowerShell).

func NormalizePath

func NormalizePath(path string) string

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

func ShellCommandArgs(shell, command string) []string

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

func ShellQuote(shell, value string) string

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

func ValidateShell(shell string) error

ValidateShell checks that the shell exists and is executable. Returns an error if the shell cannot be found.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL