首页 > 解决方案 > 如何使用 ocamlfind 或 opam 获取已安装软件包的版本?

问题描述

在我的配置脚本中,我需要<package>使用ocamlfind或检查软件包的安装版本opam。我如何获得这些信息?

标签: opamocamlfind

解决方案


使用 ocamlfind:ocamlfind query -format %v <package>

此信息在运行时不直接可用ocamlfind query --help,但可与 一起使用ocamlfind query -help-format,它显示在其他格式选项中:

Formats for -format strings:
    ...
    %v         version
    ...

使用 opam:opam info -f installed-version <package>

--在未安装软件包时返回。

这来自opam info --help

  -f FIELDS, --field=FIELDS
       Only display the values of these fields. Fields can be selected
       among name, version, package, synopsis, synopsis-or-target,
       description, <field>:, installed-version, pin, source-hash,
       opam-file, all-installed-versions, available-versions,
       all-versions, repository, installed-files, vc-ref, depexts.
       Multiple fields can be separated with commas, in which case field
       titles will be printed; the raw value of any opam-file field can be
       queried by suffixing a colon character (:), e.g. --field=depopts:.

推荐阅读