summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorThomas Lacroix <toto.rigolo@free.fr>2019-07-09 20:19:38 +0200
committerCarl Lerche <me@carllerche.com>2019-07-09 11:19:38 -0700
commitf529928d877809172a0349a008f5517544cc7fdd (patch)
tree755714150b9b475b698b5144e12413ee7b80b5ac /bin
parent461eebe612b32d2f75fde35d737b10728ff428cd (diff)
chore: script updating versions in links to docs.rs (#1249)
Diffstat (limited to 'bin')
-rwxr-xr-xbin/publish4
-rwxr-xr-xbin/update-doc118
2 files changed, 122 insertions, 0 deletions
diff --git a/bin/publish b/bin/publish
index df0669f4..371d934d 100755
--- a/bin/publish
+++ b/bin/publish
@@ -61,6 +61,10 @@ while [[ $# -gt 0 ]]
do
case "$1" in
+ -h|--help)
+ echo "$USAGE"
+ exit 0
+ ;;
-v|--verbose)
VERBOSE="--verbose"
set +x
diff --git a/bin/update-doc b/bin/update-doc
new file mode 100755
index 00000000..c84e76d6
--- /dev/null
+++ b/bin/update-doc
@@ -0,0 +1,118 @@
+#!/usr/bin/env bash
+set -e
+USAGE="Update links to docs.rs in a tokio crate
+
+USAGE:
+ $(basename "$0") [OPTIONS] [CRATE] [VERSION]
+
+OPTIONS:
+ -d, --dry-run Perform a dry run (do not modify any file)
+ -h, --help Show this help text and exit"
+
+err() {
+ echo -e "\e[31m\e[1merror:\e[0m $@" 1>&2;
+}
+
+status() {
+ WIDTH=12
+ printf "\e[32m\e[1m%${WIDTH}s\e[0m %s\n" "$1" "$2"
+}
+
+c1grep() { grep "$@" || test $? = 1; }
+
+update_versions_in_doc() {
+ # Print what is being/would be done
+ if [ -n "$DRY_RUN" ]; then
+ local MSG="Would change:"
+ else
+ local MSG="Updating:"
+ fi
+ git grep -lr "docs.rs/$CRATE/" \
+ | xargs sed --quiet \
+ -E "s|docs.rs/$CRATE/[0-9.]+|docs.rs/$CRATE/$VERSION|gp" \
+ | sed -e "s/^/$MSG /"
+
+ # Apply changes if not in dry run
+ if [ -z "$DRY_RUN" ]; then
+ git grep -lr "docs.rs/$CRATE/" \
+ | xargs sed -i \
+ -E "s|docs.rs/$CRATE/[0-9.]+|docs.rs/$CRATE/$VERSION|g"
+ fi
+}
+
+update() {
+ update_versions_in_doc
+}
+
+show_outdated() {
+ OUTDATED=$(git grep -rn "docs.rs/$CRATE/" \
+ | c1grep -v "$VERSION" \
+ | sed -e 's/^/ - /')
+ if [[ -n "$OUTDATED" ]]; then
+ echo "Found the following links to docs.rs with an outdated version:"
+ echo "$OUTDATED"
+ echo
+ else
+ echo "Nothing to do."
+ exit 1
+ fi
+}
+
+while [[ $# -gt 0 ]]
+do
+
+case "$1" in
+ -h|--help)
+ echo "$USAGE"
+ exit 0
+ ;;
+ -d|--dry-run)
+ DRY_RUN="--dry-run"
+ shift
+ ;;
+ -*)
+ err "unknown flag \"$1\""
+ echo "$USAGE"
+ exit 1
+ ;;
+ *) # crate or version
+ if [ -z "$CRATE" ]; then
+ CRATE="$1"
+ elif [ -z "$VERSION" ]; then
+ VERSION="$1"
+ else
+ err "unknown positional argument \"$1\""
+ echo "$USAGE"
+ exit 1
+ fi
+ shift
+ ;;
+esac
+done
+# set -- "${POSITIONAL[@]}"
+
+if [ -z "$VERSION" ]; then
+ err "no version specified!"
+ HELP=1
+fi
+
+if [ -n "$CRATE" ]; then
+ TAG="$CRATE-$VERSION"
+else
+ err "no crate specified!"
+ HELP=1
+fi
+
+if [ -n "$HELP" ]; then
+ echo "$USAGE"
+ exit 1
+fi
+
+if [ -d "$CRATE" ]; then
+ # Does not cd in order to update everywhere
+ show_outdated && update
+else
+ err "no such crate \"$CRATE\""
+ exit 1
+fi
+