Documentation
¶
Overview ¶
Package client implements the Rocks facade — the keystone public API that composes the manif, rockspec, fetch, build, tree, deps and remote subsystems into LuaRocks operations. The native backend implements eight write ops — Install, Build, Make, Pack, Unpack, Remove, Search, Download — and returns rocks.ErrNotImplemented for the other ten; the lua backend covers the full upstream command set. Reads (List, Show, Which) are served by r.store regardless of backend; the write set is the Engine interface (engine.go).
Construct via New(cfg, opts...): the default backend is BackendNative, WithBackend(BackendLua) selects the embedded gopher-lua VM (booted lazily on the first write operation). Per-operation option structs (InstallOpts, BuildOpts, SearchOpts, ...) mirror the upstream CLI flags; Exec is the raw escape hatch that runs an arbitrary `luarocks` argv through the embedded dispatcher (BackendLua only).
Why this lives in a sub-package rather than at the module root:
- deps/ imports rocks (root) for shared data types (Rockspec, Version, VersionConstraint, …).
- The facade needs to invoke deps.Resolve.
- A direct rocks → deps import would create a cycle.
The root rocks package retains the data types and interfaces; the operational Rocks struct + methods live here in the client package. Callers spell it `client.New(cfg)`.
Subsystem references:
- rockspec.Eval / MergePlatforms / RuntimePlatforms / Validate
- fetch.Fetch / FetchWith
- build.RunBackend
- tree.Open / tree.Tree.Deploy / tree.Tree.Which
- manif.FileStore (default ManifestStore)
- deps.Resolve
- remote.NewIndex / remote.NewOrderedIndex (default RemoteIndex): each entry of Config.Servers is dispatched by its own form, so a rock server may be a local directory (`/srv/rocks`, `file:///srv/rocks`) as well as an HTTP(S) URL, and the list is queried in configuration order, first-found-wins.
Index ¶
- type AdminOpts
- type Backend
- type BuildOpts
- type ConfigOpts
- type DepsPolicy
- type DocOpts
- type DownloadOpts
- type Engine
- type InitProjectOpts
- type InstallOpts
- type InstalledRock
- type LintOpts
- type MakeOpts
- type NewVersionOpts
- type Option
- type PackOpts
- type PurgeOpts
- type RemoveOpts
- type Rocks
- func (r *Rocks) Admin(ctx context.Context, subCmd string, args []string, opts AdminOpts) error
- func (r *Rocks) Build(ctx context.Context, specPath string, opts BuildOpts) error
- func (r *Rocks) Config(ctx context.Context, opts ConfigOpts) (string, error)
- func (r *Rocks) Doc(ctx context.Context, name string, opts DocOpts) error
- func (r *Rocks) Download(ctx context.Context, name string, opts DownloadOpts) (string, error)
- func (r *Rocks) Exec(ctx context.Context, progname string, argv []string) error
- func (r *Rocks) InitProject(ctx context.Context, opts InitProjectOpts) error
- func (r *Rocks) Install(ctx context.Context, name string, opts InstallOpts) error
- func (r *Rocks) Lint(ctx context.Context, specPath string, opts LintOpts) error
- func (r *Rocks) List(ctx context.Context) ([]InstalledRock, error)
- func (r *Rocks) Make(ctx context.Context, opts MakeOpts) error
- func (r *Rocks) NewVersion(ctx context.Context, specPath string, opts NewVersionOpts) (string, error)
- func (r *Rocks) Pack(ctx context.Context, target string, opts PackOpts) (string, error)
- func (r *Rocks) Purge(ctx context.Context, opts PurgeOpts) error
- func (r *Rocks) ReadTreeManifest() (*rocks.Manifest, error)
- func (r *Rocks) Remove(ctx context.Context, name string, opts RemoveOpts) error
- func (r *Rocks) Search(ctx context.Context, pattern string, opts SearchOpts) ([]SearchResult, error)
- func (r *Rocks) Show(ctx context.Context, name string) (*ShowInfo, error)
- func (r *Rocks) Test(ctx context.Context, specPath string, opts TestOpts) error
- func (r *Rocks) Unpack(ctx context.Context, archive, destDir string) error
- func (r *Rocks) Upload(ctx context.Context, specPath string, opts UploadOpts) error
- func (r *Rocks) Which(ctx context.Context, module string) (string, bool, error)
- func (r *Rocks) WriteRockspec(ctx context.Context, url string, opts WriteRockspecOpts) (string, error)
- type SearchOpts
- type SearchResult
- type ShowInfo
- type TestOpts
- type UploadOpts
- type WriteRockspecOpts
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AdminOpts ¶
type AdminOpts struct {
// Server maps to --server <s>: the server to operate on.
Server string
// Force maps to --force where the subcommand supports it.
Force bool
}
AdminOpts tunes Admin (luarocks admin <subcmd>). See luarocks/admin/cmd/*. Admin subcommands vary widely; common cross-cutting flags are modeled and the rest are passed verbatim via the Admin args parameter.
type Backend ¶
type Backend int
Backend selects which Engine implementation a Rocks facade uses. The zero value is BackendNative — the pure-Go backend that has always served this package — so New(cfg) with no options keeps existing behavior.
const ( // BackendNative is the pure-Go implementation (nativeEngine). It is the // default (zero value) and serves all eight currently-implemented write // operations. BackendNative Backend = iota // BackendLua selects the gopher-lua backend, which boots an embedded // LuaRocks VM lazily on the first write call and serves every upstream // LuaRocks command. BackendLua )
type BuildOpts ¶
type BuildOpts struct {
// Keep, if true, leaves the staging build directory in place after a
// successful build for debugging. Default removes it.
Keep bool
}
BuildOpts tunes Build.
type ConfigOpts ¶
type ConfigOpts struct {
// Key, if set, is the `key` positional: prints that entry's value. Empty
// prints the whole effective configuration.
Key string
// Value, if set, is the `value` positional: writes Key=Value instead of
// printing.
Value string
// Unset maps to --unset: delete Key from the configuration file.
Unset bool
// Scope maps to --scope <scope> {system,user,project}.
Scope string
// JSON maps to --json: output as JSON.
JSON bool
}
ConfigOpts tunes Config (luarocks config). See cmd/config.lua.
type DepsPolicy ¶
type DepsPolicy int
DepsPolicy mirrors upstream's `--deps-mode` flag.
const ( // DepsAll resolves and installs every transitive dependency. DepsAll DepsPolicy = 0 // DepsNone installs only the named rock; missing deps cause Install // to fail. DepsNone DepsPolicy = 1 // DepsOnlyNew installs deps that aren't already in the tree. DepsOnlyNew DepsPolicy = 2 )
type DocOpts ¶
type DocOpts struct {
// Version, if set, is the `version` positional.
Version string
// Home maps to --home: open the project home page.
Home bool
// List maps to --list: list documentation files only.
List bool
}
DocOpts tunes Doc (luarocks doc). See cmd/doc.lua. Doc is tree-scoped (it looks up an installed rock), so the --tree global is emitted automatically.
type DownloadOpts ¶
type DownloadOpts struct {
// Version, if set, is the `version` positional: an exact version, or any
// constraint expression deps.ParseConstraints accepts.
Version string
// All downloads every match instead of the single best one (--all). It is
// also what makes an empty name legal, and that combination downloads
// every rock the servers offer.
All bool
// Source restricts the download to the `.src.rock` (--source). Mutually
// exclusive with Rockspec and Arch, which upstream enforces as a parser
// mutex; setting two is an error, not a silent pick.
Source bool
// Rockspec restricts the download to the bare `.rockspec` (--rockspec).
// Mutually exclusive with Source and Arch.
Rockspec bool
// Arch restricts the download to one manifest arch (--arch <arch>), e.g.
// "all" or "linux-x86_64". Mutually exclusive with Source and Rockspec.
Arch string
// Servers are searched BEFORE the configured Config.Servers rather than
// instead of them, which is what upstream's --server does — see
// SearchOpts.Servers for why this differs from InstallOpts.Servers.
Servers []string
}
DownloadOpts tunes Download (luarocks download). See cmd/download.lua.
type Engine ¶
type Engine interface {
// The eight operations the native backend already implements.
Install(ctx context.Context, name string, opts InstallOpts) error
Build(ctx context.Context, specPath string, opts BuildOpts) error
Make(ctx context.Context, opts MakeOpts) error
Pack(ctx context.Context, target string, opts PackOpts) (string, error)
Unpack(ctx context.Context, archive, destDir string) error
Remove(ctx context.Context, name string, opts RemoveOpts) error
Search(ctx context.Context, pattern string, opts SearchOpts) ([]SearchResult, error)
Download(ctx context.Context, name string, opts DownloadOpts) (string, error)
// The ten operations not yet implemented by the native backend.
// Until a backend implements them they return rocks.ErrNotImplemented.
Purge(ctx context.Context, opts PurgeOpts) error
Lint(ctx context.Context, specPath string, opts LintOpts) error
NewVersion(ctx context.Context, specPath string, opts NewVersionOpts) (string, error)
WriteRockspec(ctx context.Context, url string, opts WriteRockspecOpts) (string, error)
Doc(ctx context.Context, name string, opts DocOpts) error
Test(ctx context.Context, specPath string, opts TestOpts) error
Config(ctx context.Context, opts ConfigOpts) (string, error)
Upload(ctx context.Context, specPath string, opts UploadOpts) error
InitProject(ctx context.Context, opts InitProjectOpts) error
Admin(ctx context.Context, subCmd string, args []string, opts AdminOpts) error
}
Engine is the backend contract for every write operation a Rocks facade can perform. The public *Rocks write methods are pure delegations to the active engine; the engine is selected once at New() time and is final for the lifetime of the returned *Rocks.
Engine contains every operation both backends (native, lua) must answer for. Where a backend cannot perform an operation, its method returns rocks.ErrNotImplemented — never a silent no-op or zero-value success. Callers discriminate with errors.Is(err, rocks.ErrNotImplemented).
Read operations (List, Show, Which, ReadTreeManifest) are intentionally NOT part of Engine: they are served by the native r.store regardless of the selected backend, so they stay on *Rocks directly.
type InitProjectOpts ¶
type InitProjectOpts struct {
// Name, if set, is the `name` positional (the project name). Empty lets
// upstream derive it from the working directory.
Name string
// Version, if set, is the `version` positional.
Version string
// Reset maps to --reset: delete and regenerate the project config and
// ./lua tree.
Reset bool
}
InitProjectOpts tunes InitProject (luarocks init). See cmd/init.lua.
type InstallOpts ¶
type InstallOpts struct {
// Version, if set, narrows the candidate set to those matching this
// constraint (parsed via deps.ParseConstraints). Empty means "any
// version satisfying the rockspec's transitive constraints" — i.e.
// the resolver picks the newest.
Version string
// Servers overrides r.cfg.Servers for this Install. Empty means use
// the facade's configured servers.
Servers []string
// Deps controls whether transitive dependencies are also installed.
Deps DepsPolicy
}
InstallOpts tunes Install.
type InstalledRock ¶
type InstalledRock = rocks.InstalledRock
InstalledRock is re-exported from the root package for caller convenience (so `client.InstalledRock` and `rocks.InstalledRock` both resolve to the same type).
type LintOpts ¶
type LintOpts struct{}
LintOpts tunes Lint (luarocks lint). See cmd/lint.lua. lint takes only the rockspec positional, so there are no tunable flags.
type MakeOpts ¶
type MakeOpts struct {
// RockspecPath, if non-empty, names the rockspec to build. Empty
// means search r.cfg.WorkingDir for exactly one `*.rockspec`.
RockspecPath string
}
MakeOpts tunes Make.
type NewVersionOpts ¶
type NewVersionOpts struct {
// NewVersion, if set, is the `new_version` positional.
NewVersion string
// NewURL, if set, is the `new_url` positional (requires NewVersion).
NewURL string
// Dir maps to --dir <dir>: output directory for the new rockspec.
Dir string
// Tag maps to --tag <tag>: new SCM tag.
Tag string
}
NewVersionOpts tunes NewVersion (luarocks new_version). See cmd/new_version.lua. The rockspec/name is the method parameter.
type Option ¶
type Option func(*Rocks)
Option configures a Rocks at construction time. Apply via New(cfg, opts...).
func WithBackend ¶
WithBackend selects the Engine backend for the constructed Rocks. The selection is applied at New() time and is final for the returned *Rocks.
Example ¶
ExampleWithBackend selects the gopher-lua backend, which boots an embedded LuaRocks VM lazily on the first write operation. Construction itself never touches the VM, so it succeeds before the tree even exists.
package main
import (
"fmt"
rocks "github.com/tarantool/go-luarocks"
"github.com/tarantool/go-luarocks/client"
)
func main() {
r, err := client.New(
rocks.Config{Tree: "/opt/tt/.rocks", WorkingDir: "."},
client.WithBackend(client.BackendLua),
)
if err != nil {
panic(err)
}
fmt.Println("constructed:", r != nil)
}
Output: constructed: true
type PackOpts ¶
type PackOpts struct {
// SrcOnly, if true, produces a `.src.rock` containing the rockspec
// and original source archive rather than a deployable `.rock`.
SrcOnly bool
}
PackOpts tunes Pack.
type PurgeOpts ¶
type PurgeOpts struct {
// OldVersions maps to --old-versions: keep the highest version of each
// rock and remove the rest.
OldVersions bool
// Force maps to --force: with --old-versions, force removal even if it
// would break dependencies.
Force bool
// ForceFast maps to --force-fast: like Force but without dependency
// reporting.
ForceFast bool
}
PurgeOpts tunes Purge (luarocks purge). See cmd/purge.lua. Purge always operates on the engine's configured tree (the --tree global is mandatory upstream and is emitted automatically).
type RemoveOpts ¶
type RemoveOpts struct {
// Version, if set, restricts removal to that exact version; empty removes
// all versions of the rock (the `version` positional).
Version string
// Force maps to --force: remove even if it would break dependencies.
Force bool
// ForceFast maps to --force-fast: forced removal without reporting
// dependency issues.
ForceFast bool
// Deps maps to --deps-mode {all,one,order,none}.
Deps DepsPolicy
}
RemoveOpts tunes Remove (luarocks remove). See cmd/remove.lua.
type Rocks ¶
type Rocks struct {
// contains filtered or unexported fields
}
Rocks is the public facade. Construct via New(Config). All operations take a context and read configuration from r.cfg — no hidden global state, no os.Getwd / os.Chdir, no os.Setenv.
Write operations delegate to r.engine, which is selected once at New() time per r.backend and is final for the lifetime of the facade. Read operations (List, Show, Which, ReadTreeManifest) are served directly from r.store regardless of backend.
func New ¶
New constructs a Rocks facade from cfg. Validates the minimum required fields and wires up default implementations.
The only error New itself returns is a descriptive error when cfg.Tree is empty. Tarantool-header validation is NOT done here: New does not stat cfg.Tarantool.IncludeDir; ErrMissingTarantoolHeaders surfaces later from the operations that actually need the headers (e.g. building a C-extension rock).
opts apply at construction time. The default backend is BackendNative (the zero value); WithBackend overrides it. Backend selection is final for the returned *Rocks. The existing New(cfg) call shape is preserved by the variadic.
Example ¶
ExampleNew mirrors the README quick start: construct the facade against a tree and list what is installed (nothing, in a fresh tree).
package main
import (
"context"
"fmt"
"os"
rocks "github.com/tarantool/go-luarocks"
"github.com/tarantool/go-luarocks/client"
)
func main() {
dir, err := os.MkdirTemp("", "rocks-tree")
if err != nil {
panic(err)
}
defer func() { _ = os.RemoveAll(dir) }()
r, err := client.New(rocks.Config{
Tree: dir,
WorkingDir: ".",
Servers: []string{"http://rocks.tarantool.org/"},
})
if err != nil {
panic(err)
}
installed, err := r.List(context.Background())
if err != nil {
panic(err)
}
fmt.Println("installed rocks:", len(installed))
}
Output: installed rocks: 0
func (*Rocks) Admin ¶
Admin runs a `luarocks admin <subCmd>` repository-administration command (upstream `luarocks admin`). BackendNative returns rocks.ErrNotImplemented; BackendLua runs upstream.
func (*Rocks) Build ¶
Build evaluates the rockspec at specPath, fetches its declared source, runs the build backend, and deploys the result into r.cfg.Tree.
Unlike Install, Build does not perform dependency resolution — it assumes prerequisites are already present (matching upstream `luarocks build`).
func (*Rocks) Config ¶
Config reads or writes LuaRocks configuration and returns the printed value (upstream `luarocks config`). BackendNative returns rocks.ErrNotImplemented; BackendLua runs upstream.
func (*Rocks) Doc ¶
Doc shows or lists documentation for an installed rock (upstream `luarocks doc`). BackendNative returns rocks.ErrNotImplemented; BackendLua runs upstream.
func (*Rocks) Download ¶
Download fetches a rock file into r.cfg.WorkingDir and returns its path (upstream `luarocks download`). Both backends implement it: BackendNative resolves the artifact through remote.Search and retrieves it with fetch.File, BackendLua runs upstream and reports the file that appeared. The two agree on which file is downloaded and on the returned path; see nativeEngine.Download for the one documented difference (what a single-file download returns when it overwrote an existing file).
func (*Rocks) Exec ¶
Exec runs an arbitrary LuaRocks command line — argv is everything after `luarocks` — through the embedded upstream dispatcher, letting LuaRocks print its own output to the process stdout/stderr verbatim. It is the escape hatch tt's `tt rocks` is built on; programmatic callers should prefer the typed methods (Install, Search, …), which capture and shape their output.
progname is the program name LuaRocks prints in its usage/help text (e.g. "tt rocks"); use the library's default progname otherwise.
Exec requires BackendLua: the native engine cannot run the full CLI, so on any other backend Exec returns rocks.ErrNotImplemented.
func (*Rocks) InitProject ¶
func (r *Rocks) InitProject(ctx context.Context, opts InitProjectOpts) error
InitProject scaffolds a LuaRocks project in r.cfg.WorkingDir (upstream `luarocks init`). BackendNative returns rocks.ErrNotImplemented; BackendLua runs upstream.
func (*Rocks) Install ¶
Install installs `name` (with optional version constraint in opts.Version) into r.cfg.Tree, including transitive deps per opts.Deps. The general algorithm:
- Query the remote index for `name` candidates.
- Pick the newest version satisfying opts.Version.
- Resolve transitive deps (unless DepsNone).
- For each step in topo order: fetch source, eval rockspec, merge platforms, validate, build, deploy, update tree manifest.
- Install the requested rock itself.
Returns ErrUnsupportedRockspecFeature for unrecognized build types (bubbled up from build.RunBackend). May also surface ErrMissingTarantoolHeaders when a C-extension rock is built.
Example ¶
ExampleRocks_Install runs the complete native install pipeline — remote manifest query, rockspec fetch, source fetch, builtin build, deploy — using an in-process rock server and a local source directory, then verifies the module resolves in the tree.
package main
import (
"context"
"fmt"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
rocks "github.com/tarantool/go-luarocks"
"github.com/tarantool/go-luarocks/client"
)
func main() {
dir, err := os.MkdirTemp("", "rocks-tree")
if err != nil {
panic(err)
}
defer func() { _ = os.RemoveAll(dir) }()
srcDir := filepath.Join(dir, "src")
if err := os.MkdirAll(srcDir, 0o750); err != nil {
panic(err)
}
if err := os.WriteFile(filepath.Join(srcDir, "demo.lua"), []byte("return {}\n"), 0o600); err != nil {
panic(err)
}
spec := "package = \"demo\"\n" +
"version = \"1.0-1\"\n" +
"source = { url = \"file://" + srcDir + "\" }\n" +
"build = { type = \"builtin\", modules = { demo = \"demo.lua\" } }\n"
const manifest = `{"commands":{},"modules":{},` +
`"repository":{"demo":{"1.0-1":[{"arch":"rockspec"}]}}}`
mux := http.NewServeMux()
mux.HandleFunc("/manifest-5.1.json", func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte(manifest))
})
mux.HandleFunc("/demo-1.0-1.rockspec", func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte(spec))
})
srv := httptest.NewServer(mux)
defer srv.Close()
r, err := client.New(rocks.Config{
Tree: filepath.Join(dir, "tree"),
WorkingDir: dir,
Servers: []string{srv.URL},
})
if err != nil {
panic(err)
}
if err := r.Install(context.Background(), "demo", client.InstallOpts{}); err != nil {
panic(err)
}
_, ok, err := r.Which(context.Background(), "demo")
if err != nil {
panic(err)
}
fmt.Println("demo installed:", ok)
}
Output: demo installed: true
func (*Rocks) Lint ¶
Lint checks the syntax of a rockspec (upstream `luarocks lint`). BackendNative returns rocks.ErrNotImplemented; BackendLua runs upstream.
func (*Rocks) List ¶
func (r *Rocks) List(ctx context.Context) ([]InstalledRock, error)
List returns every rock currently installed in r.cfg.Tree.
func (*Rocks) Make ¶
Make is "build the rockspec found in cwd against the source already present in cwd" — the upstream `luarocks make` flow. It is the developer-iteration form of Build.
func (*Rocks) NewVersion ¶
func (r *Rocks) NewVersion(ctx context.Context, specPath string, opts NewVersionOpts) (string, error)
NewVersion writes an updated rockspec for a new version and returns its path (upstream `luarocks new_version`). BackendNative returns rocks.ErrNotImplemented; BackendLua runs upstream.
func (*Rocks) Pack ¶
Pack produces a .rock or .src.rock archive for `target` (rock name) in r.cfg.WorkingDir and returns its path.
- opts.SrcOnly == false: zip the installed tree at <tree>/share/tarantool/rocks/<name>/<version>/ into <name>-<ver>.rock.
- opts.SrcOnly == true: zip the rockspec only into <name>-<ver>.src.rock. (Source download lives outside the rockspec; upstream pulls source per `source.url` and inlines it. We omit that until a real packaging need surfaces — fail loud over over-engineering.)
func (*Rocks) Purge ¶
Purge removes all rocks from r.cfg.Tree (upstream `luarocks purge`). BackendNative returns rocks.ErrNotImplemented; BackendLua runs upstream.
Example ¶
ExampleRocks_Purge shows the backend contract: operations the native backend does not implement return rocks.ErrNotImplemented, discriminated with errors.Is.
package main
import (
"context"
"errors"
"fmt"
"os"
rocks "github.com/tarantool/go-luarocks"
"github.com/tarantool/go-luarocks/client"
)
func main() {
dir, err := os.MkdirTemp("", "rocks-tree")
if err != nil {
panic(err)
}
defer func() { _ = os.RemoveAll(dir) }()
r, err := client.New(rocks.Config{Tree: dir, WorkingDir: "."})
if err != nil {
panic(err)
}
err = r.Purge(context.Background(), client.PurgeOpts{})
fmt.Println("not implemented:", errors.Is(err, rocks.ErrNotImplemented))
}
Output: not implemented: true
func (*Rocks) ReadTreeManifest ¶
ReadTreeManifest is the method-style convenience for manif.FileStore.ReadTree against r.cfg.Tree. It returns the top-level manifest the tree currently advertises (composes the store).
func (*Rocks) Remove ¶
Remove uninstalls a rock from r.cfg.Tree (upstream `luarocks remove`). Both backends implement it: BackendNative deletes the requested version (or all versions when opts.Version is empty) from the on-disk tree and rewrites the tree manifest; BackendLua runs upstream `luarocks remove`.
func (*Rocks) Search ¶
func (r *Rocks) Search(ctx context.Context, pattern string, opts SearchOpts) ([]SearchResult, error)
Search queries the configured servers for rocks matching pattern (upstream `luarocks search`). Both backends implement it: BackendNative walks the manifests itself through remote.Search, BackendLua runs upstream and parses the --porcelain listing. The two agree on the result set and its order; see nativeEngine.Search for the two documented differences at the edges (an empty pattern without SearchOpts.All, and how the VM-provided rocks are versioned).
Example ¶
ExampleRocks_Search searches a rock server for every rock whose name contains the pattern. The server here is a directory on disk, which is what makes the example runnable offline; an https:// server is searched exactly the same way. Arch tells the offerings apart: "rockspec" must be built, "all" can be installed as-is.
package main
import (
"context"
"fmt"
"os"
"path/filepath"
rocks "github.com/tarantool/go-luarocks"
"github.com/tarantool/go-luarocks/client"
)
func main() {
repo, err := os.MkdirTemp("", "rocks-repo")
if err != nil {
panic(err)
}
defer func() { _ = os.RemoveAll(repo) }()
manifest := `commands = {}
modules = {}
repository = {
metrics = {
["1.0-1"] = { { arch = "rockspec" }, { arch = "all" } },
},
}
`
if err := os.WriteFile(filepath.Join(repo, "manifest"), []byte(manifest), 0o600); err != nil {
panic(err)
}
r, err := client.New(rocks.Config{Tree: repo, WorkingDir: ".", Servers: []string{repo}})
if err != nil {
panic(err)
}
found, err := r.Search(context.Background(), "metric", client.SearchOpts{})
if err != nil {
panic(err)
}
for _, m := range found {
fmt.Println(m.Name, m.Version, m.Arch)
}
}
Output: metrics 1.0-1 rockspec metrics 1.0-1 all
func (*Rocks) Show ¶
Show returns the summary info for a single rock installed in the tree. Returns an error wrapping os.ErrNotExist when the rock is not present.
func (*Rocks) Test ¶
Test runs a rock's test suite (upstream `luarocks test`). BackendNative returns rocks.ErrNotImplemented; BackendLua runs upstream.
func (*Rocks) Upload ¶
Upload publishes a rockspec to a rocks server (upstream `luarocks upload`). BackendNative returns rocks.ErrNotImplemented; BackendLua runs upstream.
func (*Rocks) Which ¶
Which resolves a dotted Lua module name to its on-disk file path in r.cfg.Tree. Returns (path, true, nil) on hit; ("", false, nil) on miss.
Example ¶
ExampleRocks_Which resolves a module name against the tree; a fresh tree has no modules, so the lookup misses.
package main
import (
"context"
"fmt"
"os"
rocks "github.com/tarantool/go-luarocks"
"github.com/tarantool/go-luarocks/client"
)
func main() {
dir, err := os.MkdirTemp("", "rocks-tree")
if err != nil {
panic(err)
}
defer func() { _ = os.RemoveAll(dir) }()
r, err := client.New(rocks.Config{Tree: dir, WorkingDir: "."})
if err != nil {
panic(err)
}
path, ok, err := r.Which(context.Background(), "no.such.module")
if err != nil {
panic(err)
}
fmt.Printf("%q %v\n", path, ok)
}
Output: "" false
func (*Rocks) WriteRockspec ¶
func (r *Rocks) WriteRockspec(ctx context.Context, url string, opts WriteRockspecOpts) (string, error)
WriteRockspec writes a starter rockspec for sources at url and returns its path (upstream `luarocks write_rockspec`). BackendNative returns rocks.ErrNotImplemented; BackendLua runs upstream.
type SearchOpts ¶
type SearchOpts struct {
// Version, if set, is the `version` positional to search for.
Version string
// Source maps to --source: return only rockspecs and source rocks.
Source bool
// Binary maps to --binary: return only pure-Lua and binary rocks.
Binary bool
// All maps to --all: list all suitable contents of the server(s).
All bool
// Servers, when non-empty, are searched BEFORE the servers in
// Config.Servers rather than instead of them — upstream's --server
// prepends to cfg.rocks_servers (cmd.lua:130), and a search reports
// everything that matches anywhere. Note this differs from
// InstallOpts.Servers, which overrides the configured list: an install
// picks one artifact, so restricting where it may come from is the useful
// meaning there.
//
// The lua backend appends a --server <s> global option per entry.
Servers []string
}
SearchOpts tunes Search (luarocks search). See cmd/search.lua. The lua backend always passes --porcelain so the listing is machine-parseable; that flag is not modeled here.
type SearchResult ¶
type SearchResult struct {
// Name is the matched rock name.
Name string
// Version is the matched version-revision string.
Version string
// Arch is the manifest arch of this offering: "rockspec" for a bare
// .rockspec, "src" for a source rock, "all" for a pure-Lua binary rock, a
// concrete "<os>-<cpu>" for a host-built one, or "installed" for a rock
// the Lua VM provides. It is what tells a rockspec from an installable
// binary rock, so tt needs it to decide between build and install.
Arch string
// Server is the repository the match came from, normalized as
// dir.normalize renders it: a local directory reads as a plain path with
// no file:// prefix and no trailing slash. A rock provided by the VM
// carries the pseudo-server "provided by VM or rocks_provided".
Server string
// Namespace is the namespace the match was found under, empty when the
// search carried none (the porcelain line then has only four fields).
Namespace string
}
SearchResult is a single match returned by Search. It mirrors the --porcelain print format of search.print_result_tree: "<name>\t<version>\t<arch>\t<repo>\t<namespace>".
type TestOpts ¶
type TestOpts struct {
// Prepare maps to --prepare: install test deps only, do not run the suite.
Prepare bool
// TestType maps to --test-type <type>: select the test suite type.
TestType string
// Args are passed through as the trailing `args` positionals to the suite.
Args []string
}
TestOpts tunes Test (luarocks test). See cmd/test.lua. The rockspec is the method parameter.
type UploadOpts ¶
type UploadOpts struct {
// SrcRock, if set, is the `src-rock` positional (a matching .src.rock).
SrcRock string
// SkipPack maps to --skip-pack: do not pack and send the source rock.
SkipPack bool
// APIKey maps to --api-key <key>.
APIKey string
// TempKey maps to --temp-key <key>.
TempKey string
// Force maps to --force: replace an existing rockspec of the same revision.
Force bool
// Sign maps to --sign: upload a signature file alongside each file.
Sign bool
}
UploadOpts tunes Upload (luarocks upload). See cmd/upload.lua. The rockspec is the method parameter.
type WriteRockspecOpts ¶
type WriteRockspecOpts struct {
// Name, if set, is the `name` positional.
Name string
// Version, if set, is the `version` positional.
Version string
// Output maps to --output <file>: write the rockspec with this filename.
Output string
// License maps to --license <string>.
License string
// Summary maps to --summary <txt>.
Summary string
// Detailed maps to --detailed <txt>.
Detailed string
// Homepage maps to --homepage <txt>.
Homepage string
// LuaVersions maps to --lua-versions <ver>.
LuaVersions string
// RockspecFormat maps to --rockspec-format <ver>.
RockspecFormat string
// Tag maps to --tag <tag>.
Tag string
// Lib maps to --lib <libs>: comma-separated C libraries to link to.
Lib string
}
WriteRockspecOpts tunes WriteRockspec (luarocks write_rockspec). See cmd/write_rockspec.lua. The location/url is the method parameter; name and version are options here since upstream can infer them.