util

package
v0.0.0-...-0b5231c Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2025 License: MPL-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Copyright Thought Machine, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0

Index

Constants

View Source
const (
	// TaskDelimiter separates a package name from a task name in a task id
	TaskDelimiter = "#"
	// RootPkgName is the reserved name that specifies the root package
	RootPkgName = "//"
)

Variables

View Source
var TaskOutputModeStrings = []string{
	fullTaskOutputString,
	noTaskOutputString,
	hashTaskOutputString,
	newTaskOutputString,
}

TaskOutputModeStrings is an array containing the string representations for task output modes

Functions

func CloseAndIgnoreError

func CloseAndIgnoreError(closer interface{ Close() error })

CloseAndIgnoreError is a utility to tell our linter that we explicitly deem it okay to not check a particular error on closing of a resource.

We use `errcheck` as a linter, which is super-opinionated about checking errors, even in places where we don't necessarily care to check the error.

`golangci-lint` has a default ignore list for this lint problem (EXC0001) which can be used to sidestep this problem but it's possibly a little too-heavy-handed in exclusion. At the expense of discoverability, this utility function forces opt-in to ignoring errors on closing of things that can be `Close`d.

func Fprintf

func Fprintf(writer io.Writer, format string, args ...interface{})

func GetPackageTaskFromId

func GetPackageTaskFromId(taskId string) (packageName string, task string)

GetPackageTaskFromId returns a tuple of the package name and target task

func GetTaskId

func GetTaskId(pkgName interface{}, target string) string

GetTaskId returns a package-task identifier (e.g @feed/thing#build).

func HelpForCobraCmd

func HelpForCobraCmd(cmd *cobra.Command) string

HelpForCobraCmd returns the help string for a given command Note that this overwrites the output for the command

func InitPrintf

func InitPrintf()

initPrintf sets up the replacements used by printf.

func IsNMLinker

func IsNMLinker(cwd string) (bool, error)

func IsPackageTask

func IsPackageTask(task string) bool

IsPackageTask returns true if a is a package-specific task (e.g. myapp#build)

func IsYarn

func IsYarn(backendName string) bool

func PositiveMod

func PositiveMod(x, d int) int

PostitiveMod returns a modulo operator like JavaScripts

func Printf

func Printf(format string, args ...interface{})

func RootTaskID

func RootTaskID(target string) string

RootTaskID returns the task id for running the given task in the root package

func RootTaskTaskName

func RootTaskTaskName(taskID string) string

RootTaskTaskName returns the task portion of a root task taskID

func Sprintf

func Sprintf(format string, args ...interface{}) string

printf is used throughout this package to print something to stderr with some replacements for pseudo-shell variables for ANSI formatting codes.

func StripPackageName

func StripPackageName(taskID string) string

StripPackageName removes the package portion of a taskID if it is a package task. Non-package tasks are returned unmodified

func ToTaskOutputModeString

func ToTaskOutputModeString(value TaskOutputMode) (string, error)

ToTaskOutputModeString converts a task output mode enum value into the string representation

func ValidateGraph

func ValidateGraph(graph *dag.AcyclicGraph) error

ValidateGraph checks that a given DAG has no cycles and no self-referential edges. We differ from the underlying DAG Validate method in that we allow multiple roots.

Types

type CacheDisabledError

type CacheDisabledError struct {
	Status  CachingStatus
	Message string
}

CacheDisabledError is an error used to indicate that remote caching is not available.

func (*CacheDisabledError) Error

func (cd *CacheDisabledError) Error() string

type CachingStatus

type CachingStatus int

CachingStatus represents the api server's perspective on whether remote caching should be allowed

const (
	// CachingStatusDisabled indicates that the server will not accept or serve artifacts
	CachingStatusDisabled CachingStatus = iota
	// CachingStatusEnabled indicates that the server will accept and serve artifacts
	CachingStatusEnabled
	// CachingStatusOverLimit indicates that a usage limit has been hit and the
	// server will temporarily not accept or serve artifacts
	CachingStatusOverLimit
	// CachingStatusPaused indicates that a customer's spending has been paused and the
	// server will temporarily not accept or serve artifacts
	CachingStatusPaused
)

func CachingStatusFromString

func CachingStatusFromString(raw string) (CachingStatus, error)

CachingStatusFromString parses a raw string to a caching status enum value

type ConcurrencyValue

type ConcurrencyValue struct {
	Value *int
	// contains filtered or unexported fields
}

ConcurrencyValue allows pflag to accept either a number or percentage of available CPUs as a value for concurrency

func (*ConcurrencyValue) Set

func (cv *ConcurrencyValue) Set(value string) error

Set implements pflag.Value.Set for ConcurrencyValue

func (*ConcurrencyValue) String

func (cv *ConcurrencyValue) String() string

String implements pflag.Value.String for ConcurrencyValue

func (*ConcurrencyValue) Type

func (cv *ConcurrencyValue) Type() string

Type implements pflag.Value.Type for ConcurrencyValue

type ExitCodeError

type ExitCodeError struct {
	ExitCode int
}

ExitCodeError is a specific error that is returned by the command to specify the exit code

func (*ExitCodeError) Error

func (e *ExitCodeError) Error() string

type Hashable

type Hashable interface {
	Hashcode() interface{}
}

Hashable is the interface used by set to get the hash code of a value. If this isn't given, then the value of the item being added to the set itself is used as the comparison value.

type Semaphore

type Semaphore chan struct{}

Semaphore is a wrapper around a channel to provide utility methods to clarify that we are treating the channel as a semaphore

func NewSemaphore

func NewSemaphore(n int) Semaphore

NewSemaphore creates a semaphore that allows up to a given limit of simultaneous acquisitions

func (Semaphore) Acquire

func (s Semaphore) Acquire()

Acquire is used to acquire an available slot. Blocks until available.

func (Semaphore) Release

func (s Semaphore) Release()

Release is used to return a slot. Acquire must be called as a pre-condition.

func (Semaphore) TryAcquire

func (s Semaphore) TryAcquire() bool

TryAcquire is used to do a non-blocking acquire. Returns a bool indicating success

type Set

type Set map[interface{}]interface{}

Set is a set data structure.

func SetFromStrings

func SetFromStrings(sl []string) Set

SetFromStrings creates a Set containing the strings from the given slice

func (Set) Add

func (s Set) Add(v interface{})

Add adds an item to the set

func (Set) Copy

func (s Set) Copy() Set

Copy returns a shallow copy of the set.

func (Set) Delete

func (s Set) Delete(v interface{})

Delete removes an item from the set.

func (Set) Difference

func (s Set) Difference(other Set) Set

Difference returns a set with the elements that s has but other doesn't.

func (Set) Filter

func (s Set) Filter(cb func(interface{}) bool) Set

Filter returns a set that contains the elements from the receiver where the given callback returns true.

func (Set) Includes

func (s Set) Includes(v interface{}) bool

Includes returns true/false of whether a value is in the set.

func (Set) Intersection

func (s Set) Intersection(other Set) Set

Intersection computes the set intersection with other.

func (Set) Len

func (s Set) Len() int

Len is the number of items in the set.

func (Set) List

func (s Set) List() []interface{}

List returns the list of set elements.

func (Set) Some

func (s Set) Some(cb func(interface{}) bool) bool

Some tests whether at least one element in the array passes the test implemented by the provided function. It returns a Boolean value.

func (Set) UnsafeListOfStrings

func (s Set) UnsafeListOfStrings() []string

UnsafeListOfStrings dangerously casts list to a string

type TaskOutputMode

type TaskOutputMode int

TaskOutputMode defines the ways titan can display task output during a run

const (
	// FullTaskOutput will show all task output
	FullTaskOutput TaskOutputMode = iota
	// NoTaskOutput will hide all task output
	NoTaskOutput
	// HashTaskOutput will display titan-computed task hashes
	HashTaskOutput
	// NewTaskOutput will show all new task output and titan-computed task hashes for cached output
	NewTaskOutput
)

func FromTaskOutputModeString

func FromTaskOutputModeString(value string) (TaskOutputMode, error)

FromTaskOutputModeString converts a task output mode's string representation into the enum value

func (*TaskOutputMode) UnmarshalJSON

func (c *TaskOutputMode) UnmarshalJSON(data []byte) error

UnmarshalJSON converts a task output mode string representation into an enum

type YarnRC

type YarnRC struct {
	NodeLinker string `yaml:"nodeLinker"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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