diff --git a/commands/package-versions/metadata b/commands/package-versions/metadata new file mode 100644 index 0000000..5437c66 --- /dev/null +++ b/commands/package-versions/metadata @@ -0,0 +1,7 @@ +# command metadata +# generated by stubbs:add-command +# Thu Oct 19 15:19:18 CDT 2017 +NAME=package-versions +DESCRIPTION="Retrieves versions for specified remote package." +OPTIONS="org repo package" +GENERATE_HELP="true" diff --git a/commands/package-versions/options.sh b/commands/package-versions/options.sh new file mode 100644 index 0000000..f724df3 --- /dev/null +++ b/commands/package-versions/options.sh @@ -0,0 +1,68 @@ +# Generated by stubbs:add-option. Do not edit, if using stubbs. +# Created: Thu Oct 19 15:21:05 CDT 2017 +# +#/ usage: bintray:package-versions --org <> --repo <> --package <> + +# _rerun_options_parse_ - Parse the command arguments and set option variables. +# +# rerun_options_parse "$@" +# +# Arguments: +# +# * the command options and their arguments +# +# Notes: +# +# * Sets shell variables for any parsed options. +# * The "-?" help argument prints command usage and will exit 2. +# * Return 0 for successful option parse. +# +rerun_options_parse() { + + unrecognized_args=() + + while (( "$#" > 0 )) + do + OPT="$1" + case "$OPT" in + --org) rerun_option_check $# $1; ORG=$2 ; shift 2 ;; + --repo) rerun_option_check $# $1; REPO=$2 ; shift 2 ;; + --package) rerun_option_check $# $1; PACKAGE=$2 ; shift 2 ;; + # help option + -\?|--help) + rerun_option_usage + exit 2 + ;; + # unrecognized arguments + *) + unrecognized_args+=("$OPT") + shift + ;; + esac + done + + # Set defaultable options. + + # Check required options are set + [[ -z "$ORG" ]] && { echo >&2 "missing required option: --org" ; return 2 ; } + [[ -z "$REPO" ]] && { echo >&2 "missing required option: --repo" ; return 2 ; } + [[ -z "$PACKAGE" ]] && { echo >&2 "missing required option: --package" ; return 2 ; } + # If option variables are declared exportable, export them. + + # Make unrecognized command line options available in $_CMD_LINE + if [ ${#unrecognized_args[@]} -gt 0 ]; then + export _CMD_LINE="${unrecognized_args[@]}" + fi + # + return 0 +} + + +# If not already set, initialize the options variables to null. +: ${ORG:=} +: ${REPO:=} +: ${PACKAGE:=} +# Default command line to null if not set +: ${_CMD_LINE:=} + + diff --git a/commands/package-versions/script b/commands/package-versions/script new file mode 100755 index 0000000..0daa4ec --- /dev/null +++ b/commands/package-versions/script @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +#/ command: bintray:package-versions: "Retrieves versions for specified remote package." +#/ usage: rerun bintray:package-versions --org <> --repo <> --package <> +#/ rerun-variables: RERUN, RERUN_VERSION, RERUN_MODULES, RERUN_MODULE_DIR +#/ option-variables: ORG REPO PACKAGE + +. $RERUN_MODULE_DIR/lib/functions.sh package-versions || { + echo >&2 "Failed loading function library." ; exit 1 ; +} + +set -o errexit -o nounset -o pipefail + +rerun_options_parse "$@" + +# Command implementation +# ---------------------- + +# - - - +scrape_bintray_package_for_versions "$ORG" "$REPO" "$PACKAGE" +# - - - + +# Done. Exit with last command exit status. +exit $? diff --git a/generator.sh b/generator.sh index 2d2c528..ee3e1c8 100644 --- a/generator.sh +++ b/generator.sh @@ -1,14 +1,29 @@ + +## modules + +## commands + +# rerun bintray: package-uri RERUN_MODULES=$(pwd)/modules ./rerun stubbs: \ add-command \ --command package-uri \ --description "Retrieves URIs for remote package artifacts of a specified version." \ --module bintray +# rerun bintray: package-versions +RERUN_MODULES=$(pwd)/modules ./rerun stubbs: \ + add-command \ + --command package-versions \ + --description "Retrieves versions for specified remote package." \ + --module bintray + +## options + # --org RERUN_MODULES=$(pwd)/modules ./rerun stubbs: \ add-option \ --arg "true" \ - --command "package-delete,package-exists,package-update,package-upload,package-upload-deb,package-uri" \ + --command "package-delete,package-exists,package-update,package-upload,package-upload-deb,package-uri,package-versions" \ --description "The bintray organization." \ --export "false" \ --long "org" \ @@ -20,7 +35,7 @@ RERUN_MODULES=$(pwd)/modules ./rerun stubbs: \ RERUN_MODULES=$(pwd)/modules ./rerun stubbs: \ add-option \ --arg "true" \ - --command "package-delete,package-exists,package-update,package-upload,package-upload-deb,package-uri" \ + --command "package-delete,package-exists,package-update,package-upload,package-upload-deb,package-uri,package-versions" \ --description "The targeted repo." \ --export "false" \ --long "repo" \ @@ -32,7 +47,7 @@ RERUN_MODULES=$(pwd)/modules ./rerun stubbs: \ RERUN_MODULES=$(pwd)/modules ./rerun stubbs: \ add-option \ --arg "true" \ - --command "package-delete,package-exists,package-update,package-upload,package-upload-deb,package-uri" \ + --command "package-delete,package-exists,package-update,package-upload,package-upload-deb,package-uri,package-versions" \ --description "The package name." \ --export "false" \ --long "package" \ diff --git a/options/org/metadata b/options/org/metadata index 82b2975..185d502 100644 --- a/options/org/metadata +++ b/options/org/metadata @@ -1,6 +1,6 @@ # option metadata # generated by stubbs:add-option -# Mon Oct 9 15:06:22 CDT 2017 +# Thu Oct 19 15:20:16 CDT 2017 NAME=org DESCRIPTION="The bintray organization." ARGUMENTS=true diff --git a/options/package/metadata b/options/package/metadata index 7e41bb0..27b8095 100644 --- a/options/package/metadata +++ b/options/package/metadata @@ -1,6 +1,6 @@ # option metadata # generated by stubbs:add-option -# Mon Oct 9 15:10:43 CDT 2017 +# Thu Oct 19 15:21:04 CDT 2017 NAME=package DESCRIPTION="The package name." ARGUMENTS=true diff --git a/options/repo/metadata b/options/repo/metadata index 34995e1..c33bf4a 100644 --- a/options/repo/metadata +++ b/options/repo/metadata @@ -1,6 +1,6 @@ # option metadata # generated by stubbs:add-option -# Mon Oct 9 15:09:15 CDT 2017 +# Thu Oct 19 15:20:43 CDT 2017 NAME=repo DESCRIPTION="The targeted repo." ARGUMENTS=true diff --git a/tests/package-versions-1-test.sh b/tests/package-versions-1-test.sh new file mode 100644 index 0000000..3c0be43 --- /dev/null +++ b/tests/package-versions-1-test.sh @@ -0,0 +1,130 @@ +#!/usr/bin/env roundup +# +#/ usage: rerun stubbs:test -m bintray -p package-versions [--answers <>] +# + +set -u + +# Helpers +# ------- +[[ -f ./functions.sh ]] && . ./functions.sh + +rerun() { + command $RERUN -M $RERUN_MODULES "$@" +} + +# Constants + +DEFAULT_ORG="example-org" +DEFAULT_REPO="example-repo" +DEFAULT_PACKAGE="example-package" + +DEFAULT_VERSIONS=$(cat < + + + + +
1.0.0/
+
1.0.3/
+
1.4.0/
+ + +END_HEREDOC +) + +DEFAULT_PACKAGE_RESPONSE_ERROR_MOCK="The requested path was not found." + +DEFAULT_CURL_MOCK_TEMPFILE="/tmp/curl_mock_counter" + +# The Plan +# -------- +describe "package-versions" + +after() { + if [ -e $DEFAULT_CURL_MOCK_TEMPFILE ]; then + rm $DEFAULT_CURL_MOCK_TEMPFILE + fi +} + +# ------------------------------ +it_errors_when_no_versions_are_found() { + # mock the curl calls + export DEFAULT_PACKAGE_RESPONSE_ERROR_MOCK + export DEFAULT_CURL_MOCK_TEMPFILE + echo 0 > $DEFAULT_CURL_MOCK_TEMPFILE + curl () { + curl_mock_counter=$(cat $DEFAULT_CURL_MOCK_TEMPFILE) + case $curl_mock_counter in + 0) + echo "$DEFAULT_PACKAGE_RESPONSE_ERROR_MOCK" + echo 1 > $DEFAULT_CURL_MOCK_TEMPFILE + return 0 + ;; + *) + echo >&2 "unexpected call to curl: $@" + return 1 + esac + + return 1 + } + export -f curl + + # invoke rerun + local exitcode= + $(rerun bintray: package-versions \ + --org "$DEFAULT_ORG" \ + --repo "$DEFAULT_REPO" \ + --package "$DEFAULT_PACKAGE") && { + echo >&2 "rerun test command succeeded"; return 1 + } || { + exitcode=$?; test $exitcode -eq 3 + } || { + echo >&2 "rerun test command failed with exit code: $exitcode"; return 1 + } +} +# ------------------------------ +it_returns_req_package_versions() { + # mock the curl calls + export DEFAULT_PACKAGE_RESPONSE_MOCK + export DEFAULT_CURL_MOCK_TEMPFILE + echo 0 > $DEFAULT_CURL_MOCK_TEMPFILE + curl () { + curl_mock_counter=$(cat $DEFAULT_CURL_MOCK_TEMPFILE) + case $curl_mock_counter in + 0) + echo "$DEFAULT_PACKAGE_RESPONSE_MOCK" + echo 1 > $DEFAULT_CURL_MOCK_TEMPFILE + return 0 + ;; + *) + echo >&2 "unexpected call to curl: $@" + return 1 + esac + + return 1 + } + export -f curl + + # invoke rerun + requested_package_versions=$(rerun bintray: package-versions \ + --org "$DEFAULT_ORG" \ + --repo "$DEFAULT_REPO" \ + --package "$DEFAULT_PACKAGE") || echo >&2 "rerun test call failed with exit code: $?" + + # validate results + test "$requested_package_versions" == "$DEFAULT_VERSIONS" +} +# ------------------------------