cmd

package
v0.3.13 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Copyright © 2026 Nikolas Pikall <nikolas.pikall@gmail.com>

SPDX-License-Identifier: MIT License See the LICENSE file in the repository root for full license text.

Copyright © 2026 Nikolas Pikall <nikolas.pikall@gmail.com>

SPDX-License-Identifier: MIT License See the LICENSE file in the repository root for full license text.

Copyright © 2026 Nikolas Pikall <nikolas.pikall@gmail.com>

SPDX-License-Identifier: MIT License See the LICENSE file in the repository root for full license text.

Copyright © 2026 Nikolas Pikall <nikolas.pikall@gmail.com>

SPDX-License-Identifier: MIT License See the LICENSE file in the repository root for full license text.

Copyright © 2026 Nikolas Pikall <nikolas.pikall@gmail.com>

SPDX-License-Identifier: MIT License See the LICENSE file in the repository root for full license text.

Copyright © 2026 Nikolas Pikall <nikolas.pikall@gmail.com>

SPDX-License-Identifier: MIT License See the LICENSE file in the repository root for full license text.

Copyright © 2026 Nikolas Pikall <nikolas.pikall@gmail.com>

SPDX-License-Identifier: MIT License See the LICENSE file in the repository root for full license text.

Copyright © 2026 Nikolas Pikall <nikolas.pikall@gmail.com>

SPDX-License-Identifier: MIT License See the LICENSE file in the repository root for full license text.

Copyright © 2026 Nikolas Pikall <nikolas.pikall@gmail.com>

SPDX-License-Identifier: MIT License See the LICENSE file in the repository root for full license text.

Copyright © 2026 Nikolas Pikall <nikolas.pikall@gmail.com>

SPDX-License-Identifier: MIT License See the LICENSE file in the repository root for full license text.

Copyright © 2026 Nikolas Pikall <nikolas.pikall@gmail.com>

SPDX-License-Identifier: MIT License See the LICENSE file in the repository root for full license text.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMissingFile       = errors.New("expected file argument")
	ErrBadImport         = errors.New("not a valid import statement")
	ErrPackageNotFound   = errors.New("package not found locally")
	ErrPackageNotInIndex = errors.New("package not found in typst universe")
	ErrFileNotFound      = errors.New("file not found")
)
View Source
var (
	ErrTooManyArguments        = errors.New("too many arguments: expected one directory path")
	ErrEmptyNamespace          = errors.New("namespace must not be empty")
	ErrPackageAlreadyInstalled = errors.New("package already installed at destination")
	ErrNotADirectory           = errors.New("path is not a directory")
)
View Source
var (
	ErrUpdateDevelopmentBuild = errors.New("cannot self-update a development build; install a tagged release first")
	ErrUpdateBrewBuild        = errors.New("gotpm was installed via Homebrew; update with: brew upgrade gotpm")
)
View Source
var (
	ErrMissingInput        = errors.New("no input: provide a file argument or pipe content via stdin")
	ErrInvalidOutputOption = errors.New("option '--output' cannot be used with multiple files or a directory")
)
View Source
var ErrInsufficientPackage = errors.New("both package and version must be specified")
View Source
var ErrMissingArgument = errors.New("argument must be provided, can be one of [major|minor|patch] or a valid semver")
View Source
var ErrNoPackages = errors.New("no packages installed")
View Source
var IgnoredFileNames = map[string]struct{}{
	".git":         {},
	".gitignore":   {},
	".typstignore": {},
}
View Source
var LibFile = []byte("#let greet(name) = [Hello #name]")

Functions

func BuildIgnoreMatcher added in v0.3.13

func BuildIgnoreMatcher(dir string) *ignore.GitIgnore

func BumpRunner added in v0.3.13

func BumpRunner(cmd *cobra.Command, args []string) error

func CheckFileExists added in v0.3.13

func CheckFileExists(path string) error

func CheckImportStatement added in v0.3.13

func CheckImportStatement(imp string, result *CheckResult, index map[string]string, indexErr error) error

func CheckImports added in v0.3.13

func CheckImports(linesCh <-chan string, resultCh chan<- *CheckResult)

func CheckPackageExists added in v0.3.13

func CheckPackageExists(imp string, result *CheckResult, index map[string]string, indexErr error) error

func CheckPackageExistsLocally added in v0.3.13

func CheckPackageExistsLocally(namespace, pkg, version string) error

func CheckPackageInTypstUniverse added in v0.3.13

func CheckPackageInTypstUniverse(pkg, version string, result *CheckResult, index map[string]string, indexErr error) error

func CheckRunner added in v0.3.13

func CheckRunner(cmd *cobra.Command, args []string) error

func CopyFile added in v0.3.13

func CopyFile(src, dest string) error

func CopyPackageFiles added in v0.3.13

func CopyPackageFiles(src, dest string) error

func Execute

func Execute()

Execute adds all child commands to the root command and sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.

func ExtractImportStatements added in v0.3.13

func ExtractImportStatements(targetFile []byte) [][]byte

func InitRunner added in v0.3.13

func InitRunner(cmd *cobra.Command, args []string) error

func InstallRunner added in v0.3.13

func InstallRunner(cmd *cobra.Command, args []string) error

func IsDirPath added in v0.3.13

func IsDirPath(path string) bool

IsDirPath reports whether path is a directory, following symlinks.

func LookupVersion added in v0.3.13

func LookupVersion(ctx context.Context, index map[string]string, pkgName string) (string, string, error)

LookupVersion queries the Typst package index first and falls back to the GitHub API for missing packages or when the index is unavailable. Returns the version, its source ("index" or "github"), and any error.

func ParsePackageRef added in v0.3.13

func ParsePackageRef(importStatement []byte) (string, string)

func PrintMissingf added in v0.3.13

func PrintMissingf(format string, a ...any)

func ReadIgnoreLines added in v0.3.13

func ReadIgnoreLines(path string) []string

func RemoveTarget added in v0.3.13

func RemoveTarget(target string) error

RemoveTarget removes target from disk. When target is a symlink, only the link is removed, not the directory it points to. When target is a regular file or directory, it is removed with all its contents.

func ResolvePackageIdentity added in v0.3.13

func ResolvePackageIdentity(args []string, flags UninstallFlags) (string, string, error)

func ResolvePackageIdentityFromWorkingDir added in v0.3.13

func ResolvePackageIdentityFromWorkingDir(args []string, version string, deleteAll bool, dir string) (string, string, error)

ResolvePackageIdentityFromWorkingDir returns the package name and version to uninstall. When a name is provided as an argument it is taken from CLI args; otherwise both are read from the typst.toml in dir.

func ResolveProvidedPath added in v0.3.13

func ResolveProvidedPath(rawPath string) (string, error)

func ResolveSourceDir added in v0.3.13

func ResolveSourceDir(args []string) (string, error)

func ResolveUninstallTarget added in v0.3.13

func ResolveUninstallTarget(pkgDir, namespace, name, version string, deleteAll bool) string

ResolveUninstallTarget builds the path of the directory to remove. When deleteAll is true and no version is given, the package directory (all versions) is targeted; otherwise a specific version directory is used.

func RunTransferJobs added in v0.3.13

func RunTransferJobs(jobs []TransferJob) error

func ScanFileForImports added in v0.3.13

func ScanFileForImports(path string, importCh chan<- string) error

func ScanPackages added in v0.3.13

func ScanPackages(root string) ([]packageNamespace, error)

ScanPackages walks root (namespace/package/version layout) and returns all installed packages, including editable (symlinked) versions.

func ShouldIgnore added in v0.3.13

func ShouldIgnore(rel string, matcher *ignore.GitIgnore) bool

func SymlinkPackage added in v0.3.13

func SymlinkPackage(src, dest string) error

SymlinkPackage creates a symlink at dest pointing to the absolute path of src. The parent directory of dest is created if it does not exist.

func UpdateFileContent added in v0.3.2

func UpdateFileContent(content *[]byte, versions map[string]Result)

UpdateFileContent updates all typst package import statements in content with the versions provided by the name→version mapping.

func ValidateDestinationConflict added in v0.3.13

func ValidateDestinationConflict(path string) error

func ValidateIsDirectory added in v0.3.13

func ValidateIsDirectory(path string) error

func ValidateNamespace added in v0.3.13

func ValidateNamespace(namespace string) error

func ValidateTargetExists added in v0.3.13

func ValidateTargetExists(target string) error

ValidateTargetExists returns an error when there is nothing at target to remove. Uses Lstat so a dangling symlink still counts as "present".

func WriteOutputContent added in v0.3.13

func WriteOutputContent(content []byte, inputFilePath string, outputPath string) error

Types

type CheckResult added in v0.3.13

type CheckResult struct {
	Items []ResultItem
}

func (*CheckResult) Add added in v0.3.13

func (r *CheckResult) Add(item ResultItem)

func (*CheckResult) HasIssues added in v0.3.13

func (r *CheckResult) HasIssues() bool

func (*CheckResult) Print added in v0.3.13

func (r *CheckResult) Print()

type Destination added in v0.3.5

type Destination struct {
	Namespace string
	Name      string
	Version   string
	Path      string
}

func BuildDestination added in v0.3.13

func BuildDestination(dataDir string, manifest internal.Manifest, namespace string) Destination

func ResolveDefaultDestination added in v0.3.13

func ResolveDefaultDestination(dataDir string, manifest internal.Manifest, opts InstallOptions) (Destination, error)

ResolveDefaultDestination is used for the standard install path. It appends namespace/name/version sub-directories to dataDir.

func ResolveOverriddenDestination added in v0.3.13

func ResolveOverriddenDestination(dataDir string, manifest internal.Manifest, opts InstallOptions) (Destination, error)

ResolveOverriddenDestination is used when --install-dir or $GOTPM_INSTALL_DIR is set. dataDir is used as the final install path without appending namespace/name/version.

type ImportIssue added in v0.3.13

type ImportIssue struct {
	Import string
	Err    error
}

ImportIssue is a hard error — a dependency that could not be found.

func (ImportIssue) IsError added in v0.3.13

func (i ImportIssue) IsError() bool

func (ImportIssue) Print added in v0.3.13

func (i ImportIssue) Print()

type InstallOptions added in v0.3.12

type InstallOptions struct {
	Force     bool
	Editable  bool
	Namespace string
}

InstallOptions holds the resolved install flags.

func ReadInstallOptions added in v0.3.13

func ReadInstallOptions(cmd *cobra.Command) (InstallOptions, error)

type Result added in v0.3.10

type Result struct {
	Name    string
	Current string
	Latest  string
}

type ResultItem added in v0.3.13

type ResultItem interface {
	Print()
	IsError() bool
}

ResultItem is implemented by any diagnostic that can be collected in a CheckResult.

type TransferJob added in v0.3.13

type TransferJob struct {
	Src string
	Dst string
}

func CollectJobs added in v0.3.13

func CollectJobs(src, dest string, matcher *ignore.GitIgnore) ([]TransferJob, error)

type UninstallFlags added in v0.3.13

type UninstallFlags struct {
	Namespace string
	Version   string
	DeleteAll bool
	IsDryRun  bool
}

func ReadUninstallFlags added in v0.3.13

func ReadUninstallFlags(cmd *cobra.Command) (UninstallFlags, error)

type VersionWarning added in v0.3.13

type VersionWarning struct {
	Package   string
	Requested string
	Latest    string
}

VersionWarning is a soft warning — import found but a newer version exists.

func (VersionWarning) IsError added in v0.3.13

func (w VersionWarning) IsError() bool

func (VersionWarning) Print added in v0.3.13

func (w VersionWarning) Print()

Jump to

Keyboard shortcuts

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