使用grep在composer.lock文件中查找包的特定版本号?

时间:2017-05-29 08:04:58

标签: grep silverstripe

我希望grep我通过我的composer.lock文件中的作曲家提取的软件包的版本号。

我已经提取了包含版本号的对象,以便在StackOverflow上轻松查看。然而,作曲家还有其他多个包被拉入,当然它们都有自己的版本号。我需要silverstripe/framework的版本号3.5.3,如下所示。

如何使用grep通过命令行执行此操作?如果有更好/更简单的方法,也可以使用其他解决方案。

composer.lock

{
            "name": "silverstripe/framework",
            "version": "3.5.3",
            "source": {
                "type": "git",
                "url": "https://github.com/silverstripe/silverstripe-framework.git",
                "reference": "a2580456bda9ff513cf80227039fc79405908f3f"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/silverstripe/silverstripe-framework/zipball/a2580456bda9ff513cf80227039fc79405908f3f",
                "reference": "a2580456bda9ff513cf80227039fc79405908f3f",
                "shasum": ""
            },
            "require": {
                "composer/installers": "~1.0",
                "php": ">=5.3.3,<7"
            },
            "require-dev": {
                "phpunit/phpunit": "~3.7"
            },
            "type": "silverstripe-module",
            "extra": {
                "branch-alias": {
                    "3.x-dev": "3.5.x-dev"
                }
            },
            "autoload": {
                "classmap": [
                    "tests/behat/features/bootstrap"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "BSD-3-Clause"
            ],
            "authors": [
                {
                    "name": "SilverStripe",
                    "homepage": "http://silverstripe.com"
                },
                {
                    "name": "The SilverStripe Community",
                    "homepage": "http://silverstripe.org"
                }
            ],
            "description": "The SilverStripe framework",
            "homepage": "http://silverstripe.org",
            "keywords": [
                "framework",
                "silverstripe"
            ],
            "time": "2017-02-20 17:01:16"
        },

1 个答案:

答案 0 :(得分:2)

jq是操作JSON数据的合适工具:

jq '.packages[] | select(.name == "silverstripe/framework").version' composer.lock
"3.5.3"