github.com/xiaq/elvish@v0.12.0/website/src/ref/epm.md (about)

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