code

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package code provides types and functions for handling process exit codes.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotParsable is returned when an exit code cannot be parsed.
	ErrNotParsable = errors.New("exit code is not parsable")
	// ErrUnsupportedType is returned when an unsupported type is provided for exit code parsing.
	ErrUnsupportedType = errors.New("unsupported type for exit code")
)

Functions

This section is empty.

Types

type Code

type Code uint8

Code represents the exit code of a process.

const (
	// Success indicates that the process completed successfully.
	//
	// This exit code is commonly used to indicate that a program has
	// executed without any errors.
	Success Code = 0
	// Failure indicates that the process failed.
	//
	// This exit code is commonly used to indicate a general error or failure
	// that does not fall under more specific categories.
	Failure Code = 1
)

func ParseCode

func ParseCode[T uint8 | int | string](code T) (Code, error)

ParseCode parses the provided code value and returns it.

The code parameter can be of type uint8, int, or string. It converts the provided value to a Code type accordingly.

If the conversion fails, it returns an error and Failure code.

func (Code) Equals

func (c Code) Equals(cmp Code) bool

Equals compares numeric exit code values by their numeric values.

This ensures that parsed/constructed Codes with the same numeric value are considered equal even if they were produced differently.

func (Code) Int

func (c Code) Int() int

Int returns the integer representation of the Code.

func (Code) Succeeded

func (c Code) Succeeded() bool

Succeeded indicates whether the Code represents a success.

Jump to

Keyboard shortcuts

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