mode

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AptProvider

type AptProvider struct{}

func (AptProvider) Detect

func (p AptProvider) Detect(ctx context.Context, req DetectRequest) (bool, error)

func (AptProvider) Name

func (p AptProvider) Name() string

func (AptProvider) Plan

func (p AptProvider) Plan(ctx context.Context, req PlanRequest) (PlanResult, error)

type BrewProvider

type BrewProvider struct{}

func (BrewProvider) Detect

func (p BrewProvider) Detect(ctx context.Context, req DetectRequest) (bool, error)

func (BrewProvider) Name

func (p BrewProvider) Name() string

func (BrewProvider) Plan

type BunProvider

type BunProvider struct{}

func (BunProvider) Detect

func (p BunProvider) Detect(ctx context.Context, req DetectRequest) (bool, error)

func (BunProvider) Name

func (p BunProvider) Name() string

func (BunProvider) Plan

func (p BunProvider) Plan(ctx context.Context, req PlanRequest) (PlanResult, error)

type CocoapodsProvider

type CocoapodsProvider struct{}

func (CocoapodsProvider) Detect

func (p CocoapodsProvider) Detect(ctx context.Context, req DetectRequest) (bool, error)

func (CocoapodsProvider) Name

func (p CocoapodsProvider) Name() string

func (CocoapodsProvider) Plan

type ComposerProvider

type ComposerProvider struct{}

func (ComposerProvider) Detect

func (p ComposerProvider) Detect(ctx context.Context, req DetectRequest) (bool, error)

func (ComposerProvider) Name

func (p ComposerProvider) Name() string

func (ComposerProvider) Plan

type DefaultExecutor

type DefaultExecutor struct{}

func (DefaultExecutor) LookPath

func (e DefaultExecutor) LookPath(file string) (string, error)

func (DefaultExecutor) Output

func (e DefaultExecutor) Output(cmd *exec.Cmd) ([]byte, error)

func (DefaultExecutor) ReadDir

func (e DefaultExecutor) ReadDir(name string) ([]os.DirEntry, error)

func (DefaultExecutor) Stat

func (e DefaultExecutor) Stat(name string) (os.FileInfo, error)

type DenoProvider

type DenoProvider struct{}

func (DenoProvider) Detect

func (p DenoProvider) Detect(ctx context.Context, req DetectRequest) (bool, error)

func (DenoProvider) Name

func (p DenoProvider) Name() string

func (DenoProvider) Plan

type DetectRequest

type DetectRequest struct {
	Exec Executor
}

type Executor

type Executor interface {
	LookPath(file string) (string, error)
	Output(*exec.Cmd) ([]byte, error)
	Stat(name string) (os.FileInfo, error)
	ReadDir(name string) ([]os.DirEntry, error)
}

type ExecutorMock

type ExecutorMock struct {
	// LookPathFunc mocks the LookPath method.
	LookPathFunc func(file string) (string, error)

	// OutputFunc mocks the Output method.
	OutputFunc func(cmd *exec.Cmd) ([]byte, error)

	// ReadDirFunc mocks the ReadDir method.
	ReadDirFunc func(name string) ([]os.DirEntry, error)

	// StatFunc mocks the Stat method.
	StatFunc func(name string) (os.FileInfo, error)
	// contains filtered or unexported fields
}

ExecutorMock is a mock implementation of Executor.

func TestSomethingThatUsesExecutor(t *testing.T) {

	// make and configure a mocked Executor
	mockedExecutor := &ExecutorMock{
		LookPathFunc: func(file string) (string, error) {
			panic("mock out the LookPath method")
		},
		OutputFunc: func(cmd *exec.Cmd) ([]byte, error) {
			panic("mock out the Output method")
		},
		ReadDirFunc: func(name string) ([]os.DirEntry, error) {
			panic("mock out the ReadDir method")
		},
		StatFunc: func(name string) (os.FileInfo, error) {
			panic("mock out the Stat method")
		},
	}

	// use mockedExecutor in code that requires Executor
	// and then make assertions.

}

func (*ExecutorMock) LookPath

func (mock *ExecutorMock) LookPath(file string) (string, error)

LookPath calls LookPathFunc.

func (*ExecutorMock) LookPathCalls

func (mock *ExecutorMock) LookPathCalls() []struct {
	File string
}

LookPathCalls gets all the calls that were made to LookPath. Check the length with:

len(mockedExecutor.LookPathCalls())

func (*ExecutorMock) Output

func (mock *ExecutorMock) Output(cmd *exec.Cmd) ([]byte, error)

Output calls OutputFunc.

func (*ExecutorMock) OutputCalls

func (mock *ExecutorMock) OutputCalls() []struct {
	Cmd *exec.Cmd
}

OutputCalls gets all the calls that were made to Output. Check the length with:

len(mockedExecutor.OutputCalls())

func (*ExecutorMock) ReadDir

func (mock *ExecutorMock) ReadDir(name string) ([]os.DirEntry, error)

ReadDir calls ReadDirFunc.

func (*ExecutorMock) ReadDirCalls

func (mock *ExecutorMock) ReadDirCalls() []struct {
	Name string
}

ReadDirCalls gets all the calls that were made to ReadDir. Check the length with:

len(mockedExecutor.ReadDirCalls())

func (*ExecutorMock) Stat

func (mock *ExecutorMock) Stat(name string) (os.FileInfo, error)

Stat calls StatFunc.

func (*ExecutorMock) StatCalls

func (mock *ExecutorMock) StatCalls() []struct {
	Name string
}

StatCalls gets all the calls that were made to Stat. Check the length with:

len(mockedExecutor.StatCalls())

type GoProvider

type GoProvider struct{}

func (GoProvider) Detect

func (p GoProvider) Detect(ctx context.Context, req DetectRequest) (bool, error)

func (GoProvider) Name

func (p GoProvider) Name() string

func (GoProvider) Plan

func (p GoProvider) Plan(ctx context.Context, req PlanRequest) (PlanResult, error)

type GolangCILintProvider

type GolangCILintProvider struct{}

func (GolangCILintProvider) Detect

func (GolangCILintProvider) Name

func (p GolangCILintProvider) Name() string

func (GolangCILintProvider) Plan

type GradleProvider

type GradleProvider struct{}

func (GradleProvider) Detect

func (p GradleProvider) Detect(ctx context.Context, req DetectRequest) (bool, error)

func (GradleProvider) Name

func (p GradleProvider) Name() string

func (GradleProvider) Plan

type MavenProvider

type MavenProvider struct{}

func (MavenProvider) Detect

func (p MavenProvider) Detect(ctx context.Context, req DetectRequest) (bool, error)

func (MavenProvider) Name

func (p MavenProvider) Name() string

func (MavenProvider) Plan

type MiseProvider

type MiseProvider struct{}

func (MiseProvider) Detect

func (p MiseProvider) Detect(ctx context.Context, req DetectRequest) (bool, error)

func (MiseProvider) Name

func (p MiseProvider) Name() string

func (MiseProvider) Plan

type ModeProvider

type ModeProvider interface {
	Name() string
	Detect(ctx context.Context, req DetectRequest) (bool, error)
	Plan(ctx context.Context, req PlanRequest) (PlanResult, error)
}

type ModeProviderMock

type ModeProviderMock struct {
	// DetectFunc mocks the Detect method.
	DetectFunc func(ctx context.Context, req DetectRequest) (bool, error)

	// NameFunc mocks the Name method.
	NameFunc func() string

	// PlanFunc mocks the Plan method.
	PlanFunc func(ctx context.Context, req PlanRequest) (PlanResult, error)
	// contains filtered or unexported fields
}

ModeProviderMock is a mock implementation of ModeProvider.

func TestSomethingThatUsesModeProvider(t *testing.T) {

	// make and configure a mocked ModeProvider
	mockedModeProvider := &ModeProviderMock{
		DetectFunc: func(ctx context.Context, req DetectRequest) (bool, error) {
			panic("mock out the Detect method")
		},
		NameFunc: func() string {
			panic("mock out the Name method")
		},
		PlanFunc: func(ctx context.Context, req PlanRequest) (PlanResult, error) {
			panic("mock out the Plan method")
		},
	}

	// use mockedModeProvider in code that requires ModeProvider
	// and then make assertions.

}

func (*ModeProviderMock) Detect

func (mock *ModeProviderMock) Detect(ctx context.Context, req DetectRequest) (bool, error)

Detect calls DetectFunc.

func (*ModeProviderMock) DetectCalls

func (mock *ModeProviderMock) DetectCalls() []struct {
	Ctx context.Context
	Req DetectRequest
}

DetectCalls gets all the calls that were made to Detect. Check the length with:

len(mockedModeProvider.DetectCalls())

func (*ModeProviderMock) Name

func (mock *ModeProviderMock) Name() string

Name calls NameFunc.

func (*ModeProviderMock) NameCalls

func (mock *ModeProviderMock) NameCalls() []struct {
}

NameCalls gets all the calls that were made to Name. Check the length with:

len(mockedModeProvider.NameCalls())

func (*ModeProviderMock) Plan

func (mock *ModeProviderMock) Plan(ctx context.Context, req PlanRequest) (PlanResult, error)

Plan calls PlanFunc.

func (*ModeProviderMock) PlanCalls

func (mock *ModeProviderMock) PlanCalls() []struct {
	Ctx context.Context
	Req PlanRequest
}

PlanCalls gets all the calls that were made to Plan. Check the length with:

len(mockedModeProvider.PlanCalls())

type Modes

type Modes []ModeProvider
Example
package main

import (
	"context"
	"encoding/json"
	"os"

	"github.com/namespacelabs/spacectl/internal/cache/mode"
)

func main() {
	detected, err := mode.DefaultModes().Detect(context.Background(), mode.DetectRequest{})
	if err != nil {
		panic(err)
	}

	result, err := detected.Plan(context.Background(), mode.PlanRequest{})
	if err != nil {
		panic(err)
	}

	err = json.NewEncoder(os.Stdout).Encode(result)
	if err != nil {
		panic(err)
	}
}

func DefaultModes

func DefaultModes() Modes

func (Modes) Detect

func (modes Modes) Detect(ctx context.Context, req DetectRequest) (Modes, error)

Detect runs detection for all modes in parallel and returns those that were detected.

func (Modes) Filter

func (modes Modes) Filter(include []string) (Modes, error)

Filter reduces modes down to those specified in the from slice.

func (Modes) Names

func (modes Modes) Names() []string

Names returns all mode names that can be used.

func (Modes) Plan

func (modes Modes) Plan(ctx context.Context, req PlanRequest) (map[string]PlanResult, error)

Plan runs planning for all modes in parallel and returns their results.

type NixProvider

type NixProvider struct{}

func (NixProvider) Detect

func (p NixProvider) Detect(ctx context.Context, req DetectRequest) (bool, error)

func (NixProvider) Name

func (p NixProvider) Name() string

func (NixProvider) Plan

func (p NixProvider) Plan(ctx context.Context, req PlanRequest) (PlanResult, error)

type NpmProvider added in v0.8.0

type NpmProvider struct{}

func (NpmProvider) Detect added in v0.8.0

func (p NpmProvider) Detect(ctx context.Context, req DetectRequest) (bool, error)

func (NpmProvider) Name added in v0.8.0

func (p NpmProvider) Name() string

func (NpmProvider) Plan added in v0.8.0

func (p NpmProvider) Plan(ctx context.Context, req PlanRequest) (PlanResult, error)

type PlanRequest

type PlanRequest struct {
	EnabledModes []string
	Exec         Executor
}

type PlanResult

type PlanResult struct {
	AddEnvs     map[string]string
	MountPaths  []string
	RemovePaths []string
}

type PlaywrightProvider

type PlaywrightProvider struct{}

func (PlaywrightProvider) Detect

func (p PlaywrightProvider) Detect(ctx context.Context, req DetectRequest) (bool, error)

func (PlaywrightProvider) Name

func (p PlaywrightProvider) Name() string

func (PlaywrightProvider) Plan

type PnpmProvider

type PnpmProvider struct{}

func (PnpmProvider) Detect

func (p PnpmProvider) Detect(ctx context.Context, req DetectRequest) (bool, error)

func (PnpmProvider) Name

func (p PnpmProvider) Name() string

func (PnpmProvider) Plan

type PoetryProvider

type PoetryProvider struct{}

func (PoetryProvider) Detect

func (p PoetryProvider) Detect(ctx context.Context, req DetectRequest) (bool, error)

func (PoetryProvider) Name

func (p PoetryProvider) Name() string

func (PoetryProvider) Plan

type PythonProvider

type PythonProvider struct{}

func (PythonProvider) Detect

func (p PythonProvider) Detect(ctx context.Context, req DetectRequest) (bool, error)

func (PythonProvider) Name

func (p PythonProvider) Name() string

func (PythonProvider) Plan

type RubyProvider

type RubyProvider struct{}

func (RubyProvider) Detect

func (p RubyProvider) Detect(ctx context.Context, req DetectRequest) (bool, error)

func (RubyProvider) Name

func (p RubyProvider) Name() string

func (RubyProvider) Plan

type RustProvider

type RustProvider struct{}

func (RustProvider) Detect

func (p RustProvider) Detect(ctx context.Context, req DetectRequest) (bool, error)

func (RustProvider) Name

func (p RustProvider) Name() string

func (RustProvider) Plan

type SwiftPMProvider

type SwiftPMProvider struct{}

func (SwiftPMProvider) Detect

func (p SwiftPMProvider) Detect(ctx context.Context, req DetectRequest) (bool, error)

func (SwiftPMProvider) Name

func (p SwiftPMProvider) Name() string

func (SwiftPMProvider) Plan

type UVProvider

type UVProvider struct{}

func (UVProvider) Detect

func (p UVProvider) Detect(ctx context.Context, req DetectRequest) (bool, error)

func (UVProvider) Name

func (p UVProvider) Name() string

func (UVProvider) Plan

func (p UVProvider) Plan(ctx context.Context, req PlanRequest) (PlanResult, error)

type XcodeProvider

type XcodeProvider struct{}

func (XcodeProvider) Detect

func (p XcodeProvider) Detect(ctx context.Context, req DetectRequest) (bool, error)

func (XcodeProvider) Name

func (p XcodeProvider) Name() string

func (XcodeProvider) Plan

Experimental: Xcode compilation cache can be huge.

type YarnProvider

type YarnProvider struct{}

func (YarnProvider) Detect

func (p YarnProvider) Detect(ctx context.Context, req DetectRequest) (bool, error)

func (YarnProvider) Name

func (p YarnProvider) Name() string

func (YarnProvider) Plan

Jump to

Keyboard shortcuts

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