Created
April 29, 2015 06:50
-
-
Save vimishor/e770294b39f4e83a3136 to your computer and use it in GitHub Desktop.
Search packagist.org from CLI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env sh | |
# | |
# Search packagist.org from CLI with support for sorting results by the number | |
# of downloads or favorites. | |
# | |
# Temporary solution for https://github.com/composer/packagist/issues/365 | |
# | |
# Dependencies: | |
# - [curl](http://curl.haxx.se/) | |
# - [jq](http://stedolan.github.io/jq/) | |
# | |
set -o errexit | |
PER_PAGE=25 | |
MAX_RESULTS=5 | |
SORT_BY="downloads" | |
JQ_BIN=$(which jq) | |
CURL_BIN=$(which curl) | |
_show_usage () { | |
cat << EOF | |
usage: $0 [-l|--limit <results>] | |
[-s|--sort <downloads|favorites>] | |
[-h|--help] | |
<search> | |
EOF | |
} | |
while [ $# -gt 1 ] | |
do | |
key="$1" | |
case $key in | |
-l|--limit) | |
if [ "$2" -gt 100 ] || [ "$2" -lt 25 ]; then | |
echo "[Error]: Limit should be between 25 and 100" | |
exit 1 | |
else | |
PER_PAGE="$2" | |
shift | |
fi | |
;; | |
-s|--sort) | |
if [ "$2" = "downloads" ] || [ "$2" = "favorites" ]; then | |
SORT_BY="$2" | |
shift | |
else | |
echo "[Error]: Can't sort by $2" | |
exit 1 | |
fi | |
;; | |
-h|--help) | |
_show_usage | |
exit 0 | |
;; | |
*) | |
_show_usage | |
exit 0 | |
;; | |
esac | |
shift | |
done | |
if [ "$1" = "" ]; then | |
_show_usage | |
fi | |
RESULTS_START=$((PER_PAGE - MAX_RESULTS)) | |
$CURL_BIN -s "https://packagist.org/search.json?per_page=$PER_PAGE&q=$1" | $JQ_BIN "[ .results[]] | sort_by(.${SORT_BY}) | .[$RESULTS_START:$PER_PAGE]" |
Dont work on MacOS 10.14.5, i run:
./packagist-search.sh -s=downloads laraveld-vote
and its return nothing.
Any updates here?
Thanks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Notes:
--limit <no>
(max: 100).MAX_RESULTS=5