From a088074a1e787e03299d0418e790fab18ccdd830 Mon Sep 17 00:00:00 2001 From: manuel Date: Tue, 7 Jan 2025 00:02:40 +0200 Subject: [PATCH] [eos-bash-shared] small code reorganization in eos-pkg-changelog --- eos-pkg-changelog | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/eos-pkg-changelog b/eos-pkg-changelog index abe80b5..3cc31a6 100755 --- a/eos-pkg-changelog +++ b/eos-pkg-changelog @@ -13,7 +13,7 @@ Usage: $progname [options] package-name(s) Options: --help, -h This help. --github Uses github for showing the changelog. --gitlab Uses gitlab for showing the changelog. - --parameters Show supported package names and options. + --parameters Show supported package names and options. Implies option -d. --clfile=X, -c=X Replace PKG_CHANGELOGS array with a new one in (bash) file 'X'. --detect-clfile, -d Detects possible changelog file at '$clfile_def'. --url, -u Simply print the changelog URL instead of opening it in a browser. @@ -22,6 +22,28 @@ EOF [ "$1" ] && exit $1 } +DumpPkgnames() { + declare -p PKG_CHANGELOGS | sed 's|\[|\n\[|g' | grep "^\[" | sed -E 's|^\[([^]]*).*|\1|' +} +DumpOptions() { + local sopts2=${sopts//:/} + local lopts2=${lopts//:/} + printf "%s\n" ${sopts2//?/-& }--${lopts2//,/ --} +} +DetectClFile() { + local mode="$1" + clfile="$clfile_def" + if [ -e "$clfile" ] ; then + [ "$mode" = verbose ] && INFO "reading $clfile..." + source "$clfile" || DIE "reading $clfile failed" + else + case "$REPONAME" in + endeavouros | "") ;; # $clfile not found | using predefined EndeavourOS changelog definitions + *) DIE "$clfile not found" ;; + esac + fi +} + Parameters() { local sopts="c:dhu" local lopts="help,github,gitlab,parameters,clfile:,detect-clfile,quiet,url" @@ -38,24 +60,12 @@ Parameters() { source "$clfile" || DIE "reading $clfile failed" # get new PKG_CHANGELOGS and REPONAME ;; --detect-clfile | -d) - clfile="$clfile_def" - if [ -e "$clfile" ] ; then - INFO "reading $clfile..." - source "$clfile" || DIE "reading $clfile failed" - else - case "$REPONAME" in - endeavouros | "") ;; # $clfile not found | using predefined EndeavourOS changelog definitions - *) DIE "$clfile not found" ;; - esac - fi + DetectClFile verbose ;; --parameters) - # Dump names of supported packages and options. - declare -p PKG_CHANGELOGS | sed 's|\[|\n\[|g' | grep "^\[" | sed -E 's|^\[([^]]*).*|\1|' - - local sopts2=${sopts//:/} - local lopts2=${lopts//:/} - printf "%s\n" ${sopts2//?/-& }--${lopts2//,/ --} + DetectClFile + DumpPkgnames + DumpOptions exit 0 ;; --github | --gitlab) preferred_site=${1:2} ;;