From b5d5402e439f5edfd642fb4f680d596f5992e874 Mon Sep 17 00:00:00 2001 From: Levente Polyak Date: Mon, 10 Oct 2022 00:37:51 +0200 Subject: src: modularize repo layout into a library This will greatly help us to structure the functionality and commands in a more sane way. We will distribute the sources as actual libraries and reuse code with imports instead of processing everything with m4 and duplicating a lot of code. --- src/lib/repo/web.sh | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 src/lib/repo/web.sh (limited to 'src/lib/repo/web.sh') diff --git a/src/lib/repo/web.sh b/src/lib/repo/web.sh new file mode 100644 index 0000000..3fa214d --- /dev/null +++ b/src/lib/repo/web.sh @@ -0,0 +1,84 @@ +#!/bin/bash +# +# SPDX-License-Identifier: GPL-3.0-or-later + +[[ -z ${DEVTOOLS_INCLUDE_REPO_WEB_SH:-} ]] || return 0 +DEVTOOLS_INCLUDE_REPO_WEB_SH=1 + +_DEVTOOLS_LIBRARY_DIR=${_DEVTOOLS_LIBRARY_DIR:-@pkgdatadir@} +# shellcheck source=src/lib/common.sh +source "${_DEVTOOLS_LIBRARY_DIR}"/lib/common.sh +# shellcheck source=src/lib/api/gitlab.sh +source "${_DEVTOOLS_LIBRARY_DIR}"/lib/api/gitlab.sh + +set -e + + +pkgctl_repo_web_usage() { + local -r COMMAND=${_DEVTOOLS_COMMAND:-${BASH_SOURCE[0]##*/}} + cat <<- _EOF_ + Usage: ${COMMAND} [OPTIONS] [PKGBASE]... + + Open the packaging repository's website via xdg-open. If called with + no arguments, open the package cloned in the current working directory. + + OPTIONS + -h, --help Show this help text + + EXAMPLES + $ ${COMMAND} web linux +_EOF_ +} + +pkgctl_repo_web() { + local pkgbases=() + local path giturl pkgbase + + # option checking + while (( $# )); do + case $1 in + -h|--help) + pkgctl_repo_web_usage + exit 0 + ;; + --) + shift + break + ;; + -*) + die "invalid argument: %s" "$1" + ;; + *) + pkgbases=("$@") + break + ;; + esac + done + + # Check if web mode has xdg-open + if ! command -v xdg-open &>/dev/null; then + die "The web command requires 'xdg-open'" + fi + + # Check if used without pkgnames in a packaging directory + if (( ! $# )); then + path=${PWD} + if [[ ! -d "${path}/.git" ]]; then + die "Not a Git repository: ${path}" + fi + + giturl=$(git -C "${path}" remote get-url origin) + if [[ ${giturl} != *${GIT_PACKAGING_NAMESPACE}* ]]; then + die "Not a packaging repository: ${path}" + fi + + pkgbase=$(basename "${giturl}") + pkgbase=${pkgbase%.git} + pkgbases=("${pkgbase}") + fi + + for pkgbase in "${pkgbases[@]}"; do + path=$(gitlab_project_name_to_path "${pkgbase}") + xdg-open "${GIT_PACKAGING_URL_HTTPS}/${path}" + done +} -- cgit v1.2.3-70-g09d2 From 9b11b16a7e6cdfdff142ff1c5184a760673988d2 Mon Sep 17 00:00:00 2001 From: "Daniel M. Capella" Date: Fri, 26 May 2023 22:41:37 -0400 Subject: chore(doc): remove duplicate subcommand from example help text --- src/lib/repo/configure.sh | 2 +- src/lib/repo/web.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/lib/repo/web.sh') diff --git a/src/lib/repo/configure.sh b/src/lib/repo/configure.sh index 81b7d19..73300ae 100644 --- a/src/lib/repo/configure.sh +++ b/src/lib/repo/configure.sh @@ -38,7 +38,7 @@ pkgctl_repo_configure_usage() { -h, --help Show this help text EXAMPLES - $ ${COMMAND} configure * + $ ${COMMAND} * _EOF_ } diff --git a/src/lib/repo/web.sh b/src/lib/repo/web.sh index 3fa214d..45ea53b 100644 --- a/src/lib/repo/web.sh +++ b/src/lib/repo/web.sh @@ -26,7 +26,7 @@ pkgctl_repo_web_usage() { -h, --help Show this help text EXAMPLES - $ ${COMMAND} web linux + $ ${COMMAND} linux _EOF_ } -- cgit v1.2.3-70-g09d2