#!/bin/sh
# elvis: macports	-- Search macports packages (macports.org)
# ianb@erislabs.net 20091112

. surfraw || exit 1

w3_config_hook () {
def   SURFRAW_macports_by     name
}

w3_usage_hook () {
    cat <<EOF
Usage: $w3_argv0 [options] [search words]...
Description:
  Search macports packages (macports.org)
Local options:
  -by=TYPE                      Search by TYPE
      name            |          Software Title (default)
      category        |          Category
      maintainer      |          Maintainer
      variant         |          Variant
      platform        |          Platform
                                Default: $SURFRAW_macports_by
                                Environment: SURFRAW_macports_by
EOF
    w3_global_usage
}

w3_parse_option_hook () {
    opt="$1"
    optarg="$2"
    case "$opt" in
	-by*=*)     setopt   SURFRAW_macports_by           $optarg ;;
	*) return 1 ;;
    esac
    return 0
}

w3_config
w3_parse_args "$@"
# w3_args now contains a list of arguments
escaped_args=$(w3_url_of_arg $w3_args)

url="https://www.macports.org/ports.php"
if [ -n "$escaped_args" ]
then
    url="${url}?by=${SURFRAW_macports_by}&substr=${escaped_args}"
fi

w3_browse_url "$url"
