github.com/elves/elvish@v0.15.0/website/ref/epm.md (about) 1 <!-- toc --> 2 3 # Introduction 4 5 The Elvish Package Manager (`epm`) is a module bundled with Elvish for managing 6 third-party packages. 7 8 In Elvish terminology, a **module** is a `.elv` file that can be imported with 9 the `use` command, while a **package** is a collection of modules that are 10 usually kept in the same repository as one coherent project and may have 11 interdependencies. The Elvish language itself only deals with modules; the 12 concept of package is a matter of how to organize modules. 13 14 Like the `go` command, Elvish does **not** have a central registry of packages. 15 A package is simply identified by the URL of its code repository, e.g. 16 [github.com/elves/sample-pkg](https://github.com/elves/sample-pkg). To install 17 the package, one simply uses the following: 18 19 ```elvish 20 use epm 21 epm:install github.com/elves/sample-pkg 22 ``` 23 24 `epm` knows out-of-the-box how to manage packages hosted in GitHub, BitBucket 25 and GitLab, and requires the `git` command to be available. It can also copy 26 files via `git` or `rsync` from arbitrary locations (see 27 [Custom package domains](#custom-package-domains) for details). 28 29 Once installed, modules in this package can be imported with 30 `use github.com/elves/sample-pkg/...`. This package has a module named 31 `sample-mod` containing a function `sample-fn`, and can be used like this: 32 33 ```elvish-transcript 34 ~> use github.com/elves/sample-pkg/sample-mod 35 ~> sample-mod:sample-fn 36 This is a sample function in a sample module in a sample package 37 ``` 38 39 The next section describes functions in the `epm` module, using the same 40 notation as the [doc for the builtin module](builtin.html#usage-notation). 41 42 # Functions 43 44 ## install 45 46 ```elvish 47 epm:install &silent-if-installed=$false $pkg... 48 ``` 49 50 Install the named packages. By default, if a package is already installed, a 51 message will be shown. This can be disabled by passing 52 `&silent-if-installed=$true`, so that already-installed packages are silently 53 ignored. 54 55 ## installed 56 57 ```elvish 58 epm:installed 59 ``` 60 61 Return an array with all installed packages. `epm:list` can be used as an alias 62 for `epm:installed`. 63 64 ## is-installed 65 66 ```elvish 67 epm:is-installed $pkg 68 ``` 69 70 Returns a boolean value indicating whether the given package is installed. 71 72 ## metadata 73 74 ```elvish 75 epm:metadata $pkg 76 ``` 77 78 Returns a hash containing the metadata for the given package. Metadata for a 79 package includes the following base attributes: 80 81 - `name`: name of the package 82 - `installed`: a boolean indicating whether the package is currently installed 83 - `method`: method by which it was installed (`git` or `rsync`) 84 - `src`: source URL of the package 85 - `dst`: where the package is (or would be) installed. Note that this 86 attribute is returned even if `installed` is `$false`. 87 88 Additionally, packages can define arbitrary metadata attributes in a file called 89 `metadata.json` in their top directory. The following attributes are 90 recommended: 91 92 - `description`: a human-readable description of the package 93 - `maintainers`: an array containing the package maintainers, in 94 `Name <email>` format. 95 - `homepage`: URL of the homepage for the package, if it has one. 96 - `dependencies`: an array listing dependencies of the current package. Any 97 packages listed will be installed automatically by `epm:install` if they are 98 not yet installed. 99 100 ## query 101 102 ```elvish 103 epm:query $pkg 104 ``` 105 106 Pretty print the available metadata of the given package. 107 108 ## uninstall 109 110 ```elvish 111 epm:uninstall $pkg... 112 ``` 113 114 Uninstall named packages. 115 116 ## upgrade 117 118 ```elvish 119 epm:upgrade $pkg... 120 ``` 121 122 Upgrade named packages. If no package name is given, upgrade all installed 123 packages. 124 125 # Custom package domains 126 127 Package names in `epm` have the following structure: `domain/path`. The `domain` 128 is usually the hostname from where the package is to be fetched, such as 129 `github.com`. The `path` can have one or more components separated by slashes. 130 Usually, the full name of the package corresponds with the URL from where it can 131 be fetched. For example, the package hosted at 132 https://github.com/elves/sample-pkg is identified as 133 `github.com/elves/sample-pkg`. 134 135 Packages are stored under `~/.elvish/lib/` in a path identical to their name. 136 For example, the package mentioned above is stored at 137 `~/.elvish/lib/github.com/elves/sample-pkg`. 138 139 Each domain must be configured with the following information: 140 141 - The method to use to fetch packages from the domain. The two supported 142 methods are `git` and `rsync`. 143 144 - The number of directory levels under the domain directory in which the 145 packages are found. For example, for `github.com` the number of levels is 2, 146 since package paths have two levels (e.g. `elves/sample-pkg`). All packages 147 from a given domain have the same number of levels. 148 149 - Depending on the method, other attributes are needed: 150 151 - `git` needs a `protocol` attribute, which can be `https` or `http`, and 152 determines how the URL is constructed. 153 154 - `rsync` needs a `location` attribute, which must be a valid source 155 directory recognized by the `rsync` command. 156 157 `epm` includes default domain configurations for `github.com`, `gitlab.com` and 158 `bitbucket.org`. These three domains share the same configuration: 159 160 ```json 161 { 162 "method": "git", 163 "protocol": "https", 164 "levels": "2" 165 } 166 ``` 167 168 You can define your own domain by creating a file named `epm-domain.cfg` in the 169 appropriate directory under `~/.elvish/lib/`. For example, if you want to define 170 an `elvish-dev` domain which installs packages from your local `~/dev/elvish/` 171 directory, you must create the file `~/.elvish/lib/elvish-dev/epm-domain.cfg` 172 with the following JSON content: 173 174 ```json 175 { 176 "method": "rsync", 177 "location": "~/dev/elvish", 178 "levels": "1" 179 } 180 ``` 181 182 You can then install any directory under `~/dev/elvish/` as a package. For 183 example, if you have a directory `~/dev/elvish/utilities/`, the following 184 command will install it under `~/.elvish/lib/elvish-dev/utilities`: 185 186 ```elvish 187 epm:install elvish-dev/utilities 188 ``` 189 190 When you make any changes to your source directory, `epm:upgrade` will 191 synchronize those changes to `~/.elvish/lib`.