From b570fd50f9b60626a5327aac06e8103c3cb0348d Mon Sep 17 00:00:00 2001 From: LucĂ­a Andrea Illanes Albornoz Date: Mar 29 2023 12:26:52 +0000 Subject: Implements ./pkgtool.sh -e: edit package group file w/ ${EDITOR}. --- diff --git a/etc/README.md b/etc/README.md index 16d779f..24f9045 100644 --- a/etc/README.md +++ b/etc/README.md @@ -926,6 +926,7 @@ usage: ./pkgtool.sh [-a nt32|nt64] [-b debug|release] [-i|-m -M | -a nt32|nt64 Selects 32-bit or 64-bit architecture; defaults to nt64. -b debug|release Selects debug or release build kind; defaults to debug. + -e Edit package group file of single named package with ${EDITOR}. -i List package variables and dependencies of named package(s). -m Setup package archives mirror in and/or -M Setup Git repositories mirror in diff --git a/etc/pkgtool.usage b/etc/pkgtool.usage index b998bab..898e3e0 100644 --- a/etc/pkgtool.usage +++ b/etc/pkgtool.usage @@ -4,6 +4,7 @@ -a nt32|nt64 Selects 32-bit or 64-bit architecture; defaults to nt64. -b debug|release Selects debug or release build kind; defaults to debug. + -e Edit package group file of single named package with ${EDITOR}. -i List package variables and dependencies of named package(s). -m <dname> Setup package archives mirror in <dname> and/or -M <dname> Setup Git repositories mirror in <dname> diff --git a/pkgtool.sh b/pkgtool.sh index 9ea8fcb..a37e5c6 100755 --- a/pkgtool.sh +++ b/pkgtool.sh @@ -7,7 +7,7 @@ pkgtoolp_init() { local _pi_rstatus="${1#\$}" \ _pi_args_long="" \ _pi_name_base="pkgtool" \ - _pi_optstring="a:b:him:M:p:rRtv" \ + _pi_optstring="a:b:ehim:M:p:rRtv" \ _pi_prereqs=" awk bzip2 cat chmod cp date find grep hostname mkdir mktemp mv paste printf readlink rm sed sort tar test @@ -51,6 +51,7 @@ pkgtoolp_init_args() { _ppia_rc=0; if [ "$((${ARG_INFO:-0} + + ${ARG_EDIT:-0} + ${ARG_MIRROR:-0} + ${ARG_PROFILE:-0} + ${ARG_RDEPENDS:-0} @@ -61,6 +62,7 @@ pkgtoolp_init_args() { _ppia_rc=1; rtl_setrstatus "${_ppia_rstatus}" 'only one of -i, -m and/or -M, -p, -r, -R, -s, or -t must be specified.'; elif [ "$((${ARG_INFO:-0} + + ${ARG_EDIT:-0} + ${ARG_MIRROR:-0} + ${ARG_PROFILE:-0} + ${ARG_RDEPENDS:-0} @@ -89,7 +91,7 @@ pkgtoolp_init_getopts_fn() { : ${ARCH:="nt64"}; : ${BUILD_KIND:="debug"}; - ARG_INFO=0; ARG_MIRROR=0; ARG_RDEPENDS=0; + ARG_INFO=0; ARG_EDIT=0; ARG_MIRROR=0; ARG_RDEPENDS=0; ARG_RDEPENDS_FULL=0; ARG_TARBALL=0; ARG_VERBOSE=0; ;; @@ -119,6 +121,7 @@ pkgtoolp_init_getopts_fn() { a) ARCH="${OPTARG}"; _ppigf_shiftfl=2; ;; b) BUILD_KIND="${OPTARG}"; _ppigf_shiftfl=2; ;; h) cat etc/pkgtool.usage; exit 0; ;; + e) ARG_EDIT=1; _ppigf_shiftfl=1; ;; i) ARG_INFO=1; _ppigf_shiftfl=1; ;; m) ARG_MIRROR=1; if [ "${OPTARG:+1}" = 1 ]; then @@ -207,6 +210,48 @@ pkgtoolp_init_getopts_fn() { }; # }}} +# {{{ pkgtoolp_edit($_rstatus, $_pkg_name) +pkgtoolp_edit() { + local _ppe_rstatus="${1}" _ppe_pkg_name="${2}" \ + _ppe_fname="" _ppe_group_fname="" _ppe_group_name="" _ppe_patch_idx=0 _ppe_pkg_disabled="" \ + _ppe_pkg_finished="" _ppe_pkg_name_uc="" _ppe_pkg_names="" _ppe_pkg_vars="" _ppe_rc=0; + rtl_toupper2 \$_ppe_pkg_name \$_ppe_pkg_name_uc; + + if ! ex_pkg_load_groups \$_ppe_groups \$_ppe_groups_noauto; then + _ppi_rc=1; + rtl_setrstatus "${_ppi_rstatus}" 'Error: failed to load build groups.'; + elif ! ex_pkg_find_package \$_ppe_group_name "${_ppe_groups}" "${_ppe_pkg_name}"; then + _ppe_rc=1; + rtl_setrstatus "${_ppe_rstatus}" 'Error: unknown package \`'"${_ppe_pkg_name}'"'.'; + elif ! ex_pkg_get_packages \$_ppe_pkg_names "${_ppe_group_name}"; then + _ppe_rc=1; + rtl_setrstatus "${_ppe_rstatus}" 'Error: failed to expand package list of build group \`'"${_ppe_group_name}'"'.'; + elif ! ex_pkg_env "${DEFAULT_BUILD_STEPS}" "${DEFAULT_BUILD_VARS}"\ + "${_ppe_group_name}" "${_ppe_pkg_name}" "" "${BUILD_WORKDIR}"; then + _ppe_rc=1; + rtl_setrstatus "${_ppe_rstatus}" 'Error: failed to set package environment for \`'"${_ppe_pkg_name}'"'.'; + else + rtl_get_var_unsafe \$_ppe_group_fname -u "PKG_${_ppe_pkg_name}_GROUP_FNAME"; + + case "${EDITOR}" in + "") + rtl_setrstatus "${_ppe_rstatus}" 'Error: \${EDITOR} unset.'; + ;; + + vi|vim|nvi|nvim) + "${EDITOR}" "${_ppe_group_fname}" "+/PKG_${_ppe_pkg_name_uc}_/"; + _ppe_rc="${?}"; + ;; + *) + "${EDITOR}" "${_ppe_group_fname}"; + _ppe_rc="${?}"; + ;; + esac; + fi; + + return "${_ppe_rc}"; +}; +# }}} # {{{ pkgtoolp_info($_rstatus, $_pkg_name) pkgtoolp_info() { local _ppi_rstatus="${1}" _ppi_pkg_name_list="${2}" \ @@ -644,6 +689,7 @@ pkgtool() { _status="Error: ${_status}"; else case "1" in + "${ARG_EDIT:-0}") pkgtoolp_edit \$_status "${PKGTOOL_PKG_NAME}"; ;; "${ARG_INFO:-0}") pkgtoolp_info \$_status "${PKGTOOL_PKG_NAME}"; ;; "${ARG_MIRROR:-0}") pkgtoolp_mirror \$_status "${ARG_MIRROR_DNAME}" "${ARG_MIRROR_DNAME_GIT}"; ;; "${ARG_PROFILE:-0}") pkgtoolp_profile \$_status "${ARG_PROFILE_LOG_FNAME}"; ;;