ant add
ant add <path> # the highest release, under the last segment of the path
ant add <path>@<version> # that version
ant add <name>:<path> # under a name you choose
ant add --dev <path> # under devDependencies, for test filesant add adds a package to the project file, ant.json, or changes the entry the file has for it. It then selects the version of every package the project uses, fetches the ones the store lacks, and writes ant.lock. It takes one package or several.
Add a package
$ ant add example.com/slug
ant: fetching example.com/slug 2.0.0
+ example.com/slug 2.0.0The project file is the ant.json in the current directory or the nearest directory above. With none, ant add creates one in the current directory. An ant.json makes one project of every script in its directory and below, so a script there that pins a version in an import stops loading until it imports by name.
{
"dependencies": {
"slug": "example.com/slug@2.0.0"
}
}A program of the project imports the package by the name of its entry:
import "slug" Slug
println(Slug.make("Hello, Ant"))hello-antStandard output lists what changed in the lock: + path version for a line added and - path version for a line removed, in the order of the lock. A version that changed is one of each. A fetch says so on standard error.
Which version
A version you write has to be a tag of the repository: 1.2.0 is the tag v1.2.0. Without a version:
- A package the project file does not have gets the highest release among the repository's tags.
- A package it has already gets the highest release of the line its entry is in, as
ant updategives it. Adding a package again never moves it to another line. - Where there is no release, the highest prerelease stands in for it.
Which entry
With name:, ant add replaces the entry of that name or adds a new one. Without a name it looks for the path in the project file:
When no entry has the path, it adds one, named by the last segment of the path.
With a version, it changes the entry that has the path and the version's line. When there is none and one entry has the path, it changes that one, which moves to the other line:
sh$ ant add example.com/slug@1.2.0 ant: fetching example.com/slug 1.2.0 + example.com/slug 1.2.0 - example.com/slug 2.0.0With no version, it changes the one entry that has the path.
When another entry has the name it would give, or several entries have the path, it stops and asks for
name::textant add: example.com/slug is in the project file as slug and slug2: say which is meant, as slug:example.com/slug
To use two lines of a package side by side, give the second a name of its own:
ant add slug1:example.com/slug@1.2.0A package has one name for each line, so ant add refuses a change that would give one path and line two names. To rename an entry, remove it and add it again.
Dev dependencies
--dev puts the entry under devDependencies, which only test files import. Without it the entry goes under dependencies. Either way it leaves the other section, so ant add example.com/golden without --dev moves a dev dependency to dependencies.
ant add --dev example.com/goldenWhat it writes
ant add changes all or nothing. It writes ant.json and ant.lock only after every package was selected and fetched, so a failure leaves both as they were.
It writes ant.json whole, in one form: two spaces of indentation, main, bin, dependencies, then devDependencies, a section with nothing in it left out, the names of each section sorted, and a newline at the end.
Exit status
| Exit status | When |
|---|---|
0 | the files were written |
1 | a package cannot be fetched or is refused, a version has no tag, or an entry is not clear |
2 | the usage is wrong: an unknown flag, no package, or an argument such as yaml or host/x@v1.2 that is not a path or a version |
