[152523] contrib/mp-buildbot/mpbb
larryv at macports.org
larryv at macports.org
Sun Sep 11 18:58:50 PDT 2016
Revision: 152523
https://trac.macports.org/changeset/152523
Author: larryv at macports.org
Date: 2016-09-11 18:58:50 -0700 (Sun, 11 Sep 2016)
Log Message:
-----------
mpbb: Apply defaults after option parsing
This makes it easier to implement options that depend on other options
(like `option_staging_dir` and `option_log_dir`) at the expense of
directly including the default values in the help text.
Modified Paths:
--------------
contrib/mp-buildbot/mpbb
Modified: contrib/mp-buildbot/mpbb
===================================================================
--- contrib/mp-buildbot/mpbb 2016-09-12 01:58:48 UTC (rev 152522)
+++ contrib/mp-buildbot/mpbb 2016-09-12 01:58:50 UTC (rev 152523)
@@ -4,28 +4,10 @@
# Abort on undefined variables.
set -u
-## Options and their defaults
-option_default_archive_site=https://packages.macports.org
-option_default_help=0
-option_default_port=
-option_default_prefix=/opt/local
-option_default_staging_dir=${PWD:-/tmp/mp-buildbot}/archive-staging
-option_default_svn=$(which svn)
-option_default_svn_revision=HEAD
-option_default_svn_url=https://svn.macports.org/repository/macports/trunk
-option_default_work_dir=${PWD:-/tmp/mp-buildbot}
+# shellcheck disable=SC2154
+# Don't inherit any option variables from the calling environment.
+unset "${!option_@}"
-option_archive_site=$option_default_archive_site
-option_help=$option_default_help
-option_port=$option_default_port
-option_prefix=$option_default_prefix
-option_staging_dir=$option_default_staging_dir
-option_svn=$option_default_svn
-option_svn_revision=$option_default_svn_revision
-option_svn_url=$option_default_svn_url
-option_work_dir=$option_default_work_dir
-option_log_dir="${option_work_dir}/logs"
-
# Print $0 and arguments to standard error.
# Unset IFS to ensure "$*" uses spaces as separators.
msg() (unset IFS; printf >&2 '%s: %s\n' "$0" "$*")
@@ -45,27 +27,27 @@
--archive-site URL
Base URL of the packages archive to check whether an archive was not
- published yet. Default is $option_default_archive_site.
+ published yet. Default is "https://packages.macports.org".
--help
Print this usage message.
--prefix PREFIX
The prefix of the MacPorts installation that will build the ports. Defaults
- to $option_default_prefix.
+ to "/opt/local".
--svn BINARY
Absolute path to the svn binary that you want to use for SVN operations. The
- default is to find svn in your path, which is currently $option_default_svn.
+ default is to find svn in your path.
--svn-url SVNURL
URL to a Subversion repository in a format accepted by Subversion. The
referenced folder must contain a dports and a base folder. The default is
- $option_default_svn_url.
+ "https://svn.macports.org/repository/macports/trunk".
--svn-revision REVISION
Revision number in the specified Subversion repository to checkout. Defaults
- to $option_default_svn_revision.
+ to "HEAD".
--staging-dir DIR
Directory where new distributable archives should be copied for deployment
@@ -160,7 +142,6 @@
;;
--work-dir)
option_work_dir=$2
- option_log_dir="${option_work_dir}/logs"
shift
;;
--)
@@ -169,8 +150,8 @@
;;
*)
err "Unknown option: ${key}"
- echo
- usage
+ option_help=1
+ break
;;
esac
@@ -182,6 +163,21 @@
esac
done
+# Use sensible defaults for options that weren't set on the command line.
+: "${option_port=}"
+: "${option_prefix=/opt/local}"
+: "${option_work_dir=${PWD:-/tmp/mp-buildbot}}"
+: "${option_archive_site=https://packages.macports.org}"
+: "${option_staging_dir=${option_work_dir}/archive-staging}"
+: "${option_svn=$(which svn)}"
+: "${option_svn_revision=HEAD}"
+: "${option_svn_url=https://svn.macports.org/repository/macports/trunk}"
+: "${option_help=0}"
+
+# shellcheck disable=SC2034 disable=SC2154
+# Not really options, but pretend they are because they're global.
+option_log_dir=${option_work_dir}/logs
+
## If subcommand help is requested, print that
if [[ $option_help -eq 1 ]]; then
usage
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/macports-changes/attachments/20160911/ae80eb55/attachment-0001.html>
More information about the macports-changes
mailing list