2017-05-29 35 views
1

我想grep我通過composer從我的composer.lock文件中取得的包的版本號。使用grep在composer.lock文件中查找軟件包的特定版本號?

我已經提取了包含版本號的對象,以便於在StackOverflow上查看。然而,還有其他多個軟件包被作曲者拉入,當然它們都有自己的版本號。我需要按照下面的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" 
     }, 

回答

2

jq是用於處理JSON數據的適當工具:

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

我不希望有安裝其他第三方工具。另外還會有很多其他的軟件包通過作曲家安裝,將有一個「版本」,所以不會吐出所有版本? – ifusion

+0

@ifusion,你已經寫了你已經*提取了包含版本號*的對象。所以用'jq'管道,這將是所需的版本 – RomanPerekhrest

+0

啊對不起,我的意思是我已經提取的對象爲了在stackoverflow上顯示的目的,還有其他多個包被安裝。對不起,我不是更清楚,我會編輯我原來的問題。 – ifusion

相關問題