[152528] contrib/mp-buildbot
larryv at macports.org
larryv at macports.org
Sun Sep 11 18:59:04 PDT 2016
Revision: 152528
https://trac.macports.org/changeset/152528
Author: larryv at macports.org
Date: 2016-09-11 18:59:04 -0700 (Sun, 11 Sep 2016)
Log Message:
-----------
mpbb: Implement new help system
The `--help` option has been replaced by a new `help` subcommand.
Invoking `mpbb help` displays global usage and available subcommands,
while `mpbb help <subcommand>` displays subcommand-specific usage.
Each subcommand script `mpbb-FOO` must now define a function `FOO-usage`
that prints its specific help to standard out.
Modified Paths:
--------------
contrib/mp-buildbot/mpbb
contrib/mp-buildbot/mpbb-checkout
contrib/mp-buildbot/mpbb-cleanup
contrib/mp-buildbot/mpbb-gather-archives
contrib/mp-buildbot/mpbb-install-dependencies
contrib/mp-buildbot/mpbb-install-port
contrib/mp-buildbot/mpbb-list-subports
contrib/mp-buildbot/mpbb-selfupdate
Added Paths:
-----------
contrib/mp-buildbot/mpbb-help
Modified: contrib/mp-buildbot/mpbb
===================================================================
--- contrib/mp-buildbot/mpbb 2016-09-12 01:59:00 UTC (rev 152527)
+++ contrib/mp-buildbot/mpbb 2016-09-12 01:59:04 UTC (rev 152528)
@@ -14,60 +14,32 @@
err() { msg error: "$@"; }
warn() { msg warning: "$@"; }
-usage() {
- cols=$(tput cols) || cols=80
+mpbb-usage() {
+ # "prog" is defined in mpbb-help.
+ # shellcheck disable=SC2154
+ cat <<EOF
+usage: $prog [<global options>] <command> [<args>]
- fmt -w $(( cols - 8 )) >&2 <<-EOF
-Usage: $0 COMMAND [OPTION...]
+Build MacPorts ports in a continuous integration environment.
-mpbb, a script to help build MacPorts ports in a continous integration
-environment.
+Global options:
-OPTIONS
+ --prefix=<path>
+ The prefix of the MacPorts installation that will be used for
+ building ports. Defaults to \`/opt/local'.
- --archive-site=URL
- Base URL of the packages archive to check whether an archive was not
- published yet. Default is "https://packages.macports.org".
+ --work-dir=<path>
+ A working directory to be used for storing temporary files,
+ accessible by the MacPorts installation specified with \`--prefix'.
+ The directory should persist between runs of \`mpbb'. Defaults to
+ the value of \$PWD or \`/tmp/mp-buildbot'.
- --help
- Print this usage message.
+Available commands:
- --prefix=PREFIX
- The prefix of the MacPorts installation that will build the ports. Defaults
- to "/opt/local".
+ ${cmds[0]}$(printf ', %s' "${cmds[@]:1}")
- --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.
-
- --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
- "https://svn.macports.org/repository/macports/trunk".
-
- --svn-revision=REVISION
- Revision number in the specified Subversion repository to checkout. Defaults
- to "HEAD".
-
- --staging-dir=DIR
- Directory where new distributable archives should be copied for deployment
- on the archive server. Defaults to the 'archive-staging' subfolder in the
- current directory.
-
- --work-dir=WORKDIR
- A scratch area that mpbb will use to put temporary files, ideally kept
- between builds. Your MacPorts installation in --prefix needs to be able to
- access this location. Defaults to your current directory, or
- /tmp/mp-buildbot if \$PWD isn't set.
+Run \`$prog help <command>' for per-command help.
EOF
-
- printf >&2 "\nCOMMANDS\n"
- for command in "${commands[@]}"; do
- printf >&2 " %s\n" "$command"
- printf " %s\n\n" "$("${command}-help" | tr '\n' ' ')" | fmt -w $(( cols - 8 )) >&2
- done
-
- exit 2
}
# TODO Documentation, obviously :)
@@ -86,7 +58,7 @@
;;
1)
# getopt(1) will print the bad argument to standard error.
- echo >&2 "Try \`$0 --help' for more information."
+ echo >&2 "Try \`$0 help' for more information."
return 2
;;
*)
@@ -138,13 +110,12 @@
fi
# Process options.
-parseopt help,prefix:,work-dir: "$@" || exit
+parseopt prefix:,work-dir: "$@" || exit
# 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_help=0}"
# shellcheck disable=SC2034 disable=SC2154
# Not really options, but pretend they are because they're global.
@@ -156,15 +127,18 @@
set -- ${args+"${args[@]}"}
# Load the subcommand implementations. Each sourced script "mpbb-FOO"
-# must define functions "FOO" and "FOO-help".
+# must define functions "FOO" and "FOO-usage".
cmds=()
+usages=(mpbb-usage)
thisdir=$(cd "$(dirname "$0")" && pwd)
for cmdfile in "$thisdir/mpbb-"*; do
# Unfortunately ShellCheck does not currently support following multiple
# files, so we'll just disable the warning.
# shellcheck disable=SC1090
if . "$cmdfile"; then
- cmds+=("${cmdfile##*/mpbb-}")
+ cmd=${cmdfile##*/mpbb-}
+ cmds+=("$cmd")
+ usages+=("${cmd}-usage")
else
err "failed to load subcommand script \`$cmdfile'"
exit 3
@@ -173,7 +147,8 @@
if (( $# < 1 )); then
err "No command specified"
- usage
+ echo >&2 "Try \`$0 help' for more information."
+ exit 2
fi
subcmd=$1
@@ -185,14 +160,10 @@
done
if (( $? != 0 || ${#cmds[@]} == 0 )); then
err "Unknown command \`$command'"
- usage
+ echo >&2 "Try \`$0 help' for more information."
+ exit 2
fi
-## If subcommand help is requested, print that
-if [[ $option_help -eq 1 ]]; then
- usage
-fi
-
## Otherwise, run the command and deal with errors
PORTSRC=${option_work_dir}/macports.conf "$subcmd" "$@"
readonly rc=$?
Modified: contrib/mp-buildbot/mpbb-checkout
===================================================================
--- contrib/mp-buildbot/mpbb-checkout 2016-09-12 01:59:00 UTC (rev 152527)
+++ contrib/mp-buildbot/mpbb-checkout 2016-09-12 01:59:04 UTC (rev 152528)
@@ -5,12 +5,32 @@
# This script is sourced by the mpbb wrapper script.
# Do not execute this directly!
+checkout-usage() {
+ # "prog" is defined in mpbb-help.
+ # shellcheck disable=SC2154
+ cat <<EOF
+usage: $prog [<global opts>] checkout [<opts>]
-checkout-help() {
- cat <<EOF
-Update or checkout a working copy of the ports tree from --svn-url to specific
-SVN revision (--svn-revision), update or create the PortIndex and configure
-the MacPorts installation to use this ports tree.
+Obtain a working copy of the jobs tools and ports tree and configure
+MacPorts to use the latter as a port source.
+
+Options:
+
+ --svn=<path>
+ A command-line Subversion client. Defaults to the first \`svn'
+ executable found in \$PATH.
+
+ --svn-url=<URL>
+ URL to a Subversion repository that contains \`dports' and
+ \`base/portmgr/jobs' subdirectories. Only used when checking out
+ a new working copy. Defaults to
+ \`https://svn.macports.org/repository/macports/trunk'.
+
+ --svn-revision=<rev>
+ Revision number at which the ports tree will be checked out.
+ Defaults to \`HEAD'.
+
+Run \`$prog help' for global options and a list of other subcommands.
EOF
}
Modified: contrib/mp-buildbot/mpbb-cleanup
===================================================================
--- contrib/mp-buildbot/mpbb-cleanup 2016-09-12 01:59:00 UTC (rev 152527)
+++ contrib/mp-buildbot/mpbb-cleanup 2016-09-12 01:59:04 UTC (rev 152528)
@@ -5,8 +5,16 @@
# This script is sourced by the mpbb wrapper script.
# Do not execute this directly!
-cleanup-help() {
- echo "Clean up remnants from previous builds."
+cleanup-usage() {
+ # "prog" is defined in mpbb-help.
+ # shellcheck disable=SC2154
+ cat <<EOF
+usage: $prog [<global opts>] cleanup
+
+Clean up after a build.
+
+Run \`$prog help' for global options and a list of other subcommands.
+EOF
}
cleanup() {
Modified: contrib/mp-buildbot/mpbb-gather-archives
===================================================================
--- contrib/mp-buildbot/mpbb-gather-archives 2016-09-12 01:59:00 UTC (rev 152527)
+++ contrib/mp-buildbot/mpbb-gather-archives 2016-09-12 01:59:04 UTC (rev 152528)
@@ -5,9 +5,28 @@
# This script is sourced by the mpbb wrapper script.
# Do not execute this directly!
+gather-archives-usage() {
+ # "prog" is defined in mpbb-help.
+ # shellcheck disable=SC2154
+ cat <<EOF
+usage: $prog [<global opts>] gather-archives [<opts>]
-gather-archives-help() {
- echo "Gather unpublished distributable archives of the built port and its dependencies."
+Copy unpublished, distributable archives of active ports into a staging
+directory for uploading.
+
+Options:
+
+ --archive-site=<URL>
+ URL of a mirror to check for preexisting archives. Defaults to
+ \`https://packages.macports.org'.
+
+ --staging-dir=<path>
+ A directory for storing distributable archives before deployment.
+ Defaults to the \`archive-staging' subdirectory of the \`--work-dir'
+ working directory.
+
+Run \`$prog help' for global options and a list of other subcommands.
+EOF
}
gather-archives() {
Added: contrib/mp-buildbot/mpbb-help
===================================================================
--- contrib/mp-buildbot/mpbb-help (rev 0)
+++ contrib/mp-buildbot/mpbb-help 2016-09-12 01:59:04 UTC (rev 152528)
@@ -0,0 +1,37 @@
+#!/bin/bash
+# -*- coding: utf-8; mode: sh; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=sh:et:sw=4:ts=4:sts=4
+
+# Note:
+# This script is sourced by the mpbb wrapper script.
+# Do not execute this directly!
+
+help-usage() {
+ cat <<EOF
+usage: $prog help [<command>]
+
+Show usage information for \`$prog' or a specific \`$prog' subcommand.
+
+Run \`$prog help' for global options and a list of other subcommands.
+EOF
+}
+
+help() {
+ local cols helpfunc prog
+ cols=$(tput cols) || cols=80
+ # The main program should define "mpbb-usage", which is called if
+ # "mpbb help" is invoked without any arguments.
+ helpfunc=${1-mpbb}-usage
+ prog=$(basename "$0")
+ readonly cols helpfunc prog
+
+ # This loop exits with 0 if usages contains helpfunc or is empty.
+ for usage in "${usages[@]}"; do
+ [[ $usage == "$helpfunc" ]] && break
+ done
+ if (( $? != 0 || ${#usages[@]} == 0 )); then
+ err "No help available for subcommand \`${helpfunc%-usage}'"
+ return 2
+ fi
+
+ "$helpfunc" | fmt -w $((cols - 8)) >&2
+}
Modified: contrib/mp-buildbot/mpbb-install-dependencies
===================================================================
--- contrib/mp-buildbot/mpbb-install-dependencies 2016-09-12 01:59:00 UTC (rev 152527)
+++ contrib/mp-buildbot/mpbb-install-dependencies 2016-09-12 01:59:04 UTC (rev 152528)
@@ -5,9 +5,16 @@
# This script is sourced by the mpbb wrapper script.
# Do not execute this directly!
+install-dependencies-usage() {
+ # "prog" is defined in mpbb-help.
+ # shellcheck disable=SC2154
+ cat <<EOF
+usage: $prog [<global opts>] install-dependencies <port>
-install-dependencies-help() {
- echo "Build and install all dependencies of port --port."
+Build and install the dependencies of the given port.
+
+Run \`$prog help' for global options and a list of other subcommands.
+EOF
}
get-maintainers() {
Modified: contrib/mp-buildbot/mpbb-install-port
===================================================================
--- contrib/mp-buildbot/mpbb-install-port 2016-09-12 01:59:00 UTC (rev 152527)
+++ contrib/mp-buildbot/mpbb-install-port 2016-09-12 01:59:04 UTC (rev 152528)
@@ -5,9 +5,16 @@
# This script is sourced by the mpbb wrapper script.
# Do not execute this directly!
+install-port-usage() {
+ # "prog" is defined in mpbb-help.
+ # shellcheck disable=SC2154
+ cat <<EOF
+usage: $prog [<global opts>] install-port [<opts>] <port>
-install-port-help() {
- echo "Build and install the port --port itself."
+Build and install the given port.
+
+Run \`$prog help' for global options and a list of other subcommands.
+EOF
}
get-maintainers() {
Modified: contrib/mp-buildbot/mpbb-list-subports
===================================================================
--- contrib/mp-buildbot/mpbb-list-subports 2016-09-12 01:59:00 UTC (rev 152527)
+++ contrib/mp-buildbot/mpbb-list-subports 2016-09-12 01:59:04 UTC (rev 152528)
@@ -5,10 +5,16 @@
# This script is sourced by the mpbb wrapper script.
# Do not execute this directly!
+list-subports-usage() {
+ # "prog" is defined in mpbb-help.
+ # shellcheck disable=SC2154
+ cat <<EOF
+usage: $prog [<global opts>] list-subports <port> [<port2> [...]]
-list-subports-help() {
- echo "Print the name of port --port and its subports."
- echo "Alternatively, print the name and subports of multiple ports given as positional arguments."
+Print the name and subports of each given port to standard output.
+
+Run \`$prog help' for global options and a list of other subcommands.
+EOF
}
print-subports() {
Modified: contrib/mp-buildbot/mpbb-selfupdate
===================================================================
--- contrib/mp-buildbot/mpbb-selfupdate 2016-09-12 01:59:00 UTC (rev 152527)
+++ contrib/mp-buildbot/mpbb-selfupdate 2016-09-12 01:59:04 UTC (rev 152528)
@@ -5,8 +5,17 @@
# This script is sourced by the mpbb wrapper script.
# Do not execute this directly!
-selfupdate-help() {
- echo "Run selfupdate --nosync in the MacPorts installation specified by the --prefix flag"
+selfupdate-usage() {
+ # "prog" is defined in mpbb-help.
+ # shellcheck disable=SC2154
+ cat <<EOF
+usage: $prog [<global options>] selfupdate
+
+Install or update the auxiliary MacPorts base installation. (To reindex
+port sources, use \`$prog checkout'.)
+
+Run \`$prog help' for global options and a list of other subcommands.
+EOF
}
selfupdate() {
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/macports-changes/attachments/20160911/a683805d/attachment-0001.html>
More information about the macports-changes
mailing list