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

问题描述:

我想grep我通过composer从我的composer.lock文件中取得的包的版本号。使用grep在composer.lock文件中查找软件包的特定版本号?

我已经提取了包含版本号的对象,以便于在*上查看。然而,还有其他多个软件包被作曲者拉入,当然它们都有自己的版本号。我需要按照下面的silverstripe/framework3.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" 
     }, 

jq是用于处理JSON数据的适当工具:

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

我不希望有安装其他第三方工具。另外还会有很多其他的软件包通过作曲家安装,将有一个“版本”,所以不会吐出所有版本? – ifusion

+0

@ifusion,你已经写了你已经*提取了包含版本号*的对象。所以用'jq'管道,这将是所需的版本 – RomanPerekhrest

+0

啊对不起,我的意思是我已经提取的对象为了在*上显示的目的,还有其他多个包被安装。对不起,我不是更清楚,我会编辑我原来的问题。 – ifusion