pack
Types
An error which occurred during an operation.
pub type Error {
FailedToGetDirectory
FailedToCreateDirectory(
path: String,
error: simplifile.FileError,
)
FailedToWriteToFile(path: String, error: simplifile.FileError)
FailedToReadFile(path: String, error: simplifile.FileError)
FailedToDeleteDirectory(
path: String,
error: simplifile.FileError,
)
FailedToReadDirectory(
path: String,
error: simplifile.FileError,
)
RequestFailed(url: String, error: httpc.HttpError)
RequestReturnedIncorrectResponse(url: String, status_code: Int)
ResponseJsonInvalid(json.DecodeError)
FileContainedInvalidJson(json.DecodeError)
FailedToDecodeHexTarball(package: String)
}
Constructors
-
FailedToGetDirectoryFailed to find a suitable directory to store data in
-
FailedToCreateDirectory( path: String, error: simplifile.FileError, )Failed to create a directory
-
FailedToWriteToFile(path: String, error: simplifile.FileError)Failed to write to a file
-
FailedToReadFile(path: String, error: simplifile.FileError)Failed to read a file
-
FailedToDeleteDirectory( path: String, error: simplifile.FileError, )Failed to delete a directory
-
FailedToReadDirectory(path: String, error: simplifile.FileError)Failed to read a directory
-
RequestFailed(url: String, error: httpc.HttpError)Failed to send an HTTP request
-
RequestReturnedIncorrectResponse(url: String, status_code: Int)An HTTP request returned a response that was not 200 OK
-
ResponseJsonInvalid(json.DecodeError)An HTTP request returned invalid JSON
-
FileContainedInvalidJson(json.DecodeError)The cached data file contained invalid JSON
-
FailedToDecodeHexTarball(package: String)Decoding the Hex tarball for a particular package failed.
A file which is included in a package
pub type File {
TextFile(name: String, contents: String)
BinaryFile(name: String, contents: BitArray)
}
Constructors
-
TextFile(name: String, contents: String)A text file containing UTF-8 data
Arguments
- name
-
The path to the file within the package, for example
src/gleam/io.gleam - contents
-
The contents of the text file
-
BinaryFile(name: String, contents: BitArray)A binary file which doesn’t contain valid UTF-8
Arguments
- name
-
The path to the file within the package, for example
priv/data/something.bin - contents
-
The binary contents of the file
Options to configure behaviour of pack
pub type Options {
Options(
write_to_file: Bool,
refresh_package_list: Bool,
write_packages_to_disc: Bool,
read_packages_from_disc: Bool,
print_logs: Bool,
)
}
Constructors
-
Options( write_to_file: Bool, refresh_package_list: Bool, write_packages_to_disc: Bool, read_packages_from_disc: Bool, print_logs: Bool, )Arguments
- write_to_file
-
Whether or not to write the package index data to a file for caching later. It is recommended to leave this as
True, as setting it toFalsewill require sending a request to the Gleam packages API every time you need to access data. However, you may want to set it toFalseif you don’t wantpackto write to your file system. - refresh_package_list
-
If set to
True,packwill ignore any cached package information and perform a full rescan of the Gleam package index. This is useful if the cached information is outdated. - write_packages_to_disc
-
Whether or not to write packages to disc when downloading. Like
write_to_file, setting this toFalsewill require sending requests to Hex for every package every timepackis invoked. - read_packages_from_disc
-
If set to
False,packwill ignore existing source code downloaded for packages and redownload all of them. This is useful if downloaded packages are outdated and you need the newer source code. - print_logs
-
Whether or not to print out logs of operations
packis performing. It can be helpful to user experience to leave these on, as downloading from the package index can take a long time, and without logs there is no indication of progress. However, this will print a line for every single package downloaded so it may be preferable to disable it.
Information about a Gleam package, fetching from the Gleam package index.
pub type Package {
Package(
name: String,
description: String,
latest_version: String,
repository: option.Option(String),
updated_at: Int,
releases: List(Release),
)
}
Constructors
-
Package( name: String, description: String, latest_version: String, repository: option.Option(String), updated_at: Int, releases: List(Release), )
Values
pub const default_options: Options
A set of default options, the same defaults as are used by the CLI when no flags are provided.
pub fn describe_error(error: Error) -> String
Turn an error into a human-readable string.
pub fn download(
pack: Pack,
) -> Result(dict.Dict(String, List(File)), Error)
Download packages, returning a dict containing a mapping of package names to the files within the package.
pub fn download_to_disc(pack: Pack) -> Result(Nil, Error)
Download packages to disc without returning information about them.
pub fn load(options: Options) -> Result(Pack, Error)
Load state, either from a file or by fetching data from the Gleam package index,
depending on the options and whether pack has been run before.
pub fn packages_directory(pack: Pack) -> String
Returns the path to the directory containing downloaded package source code.