hive-forge: stdin beats bare positional for comment / comment-edit (closes #379)
This commit is contained in:
parent
d4bb3e4aa0
commit
1294ca2755
1 changed files with 38 additions and 16 deletions
|
|
@ -137,24 +137,41 @@ pkgs.writeShellApplication {
|
|||
}
|
||||
|
||||
cmd_comment() {
|
||||
# comment <number> [--body <text> | -f <file> | -]
|
||||
# comment <number> [--body <text> | -f <file> | -] [repo]
|
||||
# Post a comment on an issue or PR.
|
||||
# Accepts --body <text> (consistent with issue-create/pr-create),
|
||||
# -f <file>, - (stdin), or a bare positional body string.
|
||||
if [ $# -lt 1 ]; then echo "usage: hive-forge comment <number> [--body <text> | -f <file> | -]" >&2; exit 1; fi
|
||||
# Body sources, in priority order:
|
||||
# --body <text> | -f <file> | - (explicit stdin)
|
||||
# piped stdin (HEREDOC / shell pipe — `! -t 0`)
|
||||
# bare positional argument
|
||||
# Stdin wins over a bare positional so the natural
|
||||
# hive-forge comment 377 owner/repo <<EOF ...
|
||||
# form posts the HEREDOC and treats `owner/repo` as a repo
|
||||
# override — instead of silently dropping the HEREDOC on the
|
||||
# floor (closes #379).
|
||||
if [ $# -lt 1 ]; then echo "usage: hive-forge comment <number> [--body <text> | -f <file> | -] [repo]" >&2; exit 1; fi
|
||||
local _n="$1"; shift
|
||||
local _body _repo="$HIVE_FORGE_REPO"
|
||||
if [ $# -eq 0 ] || [ "''${1:-}" = "-" ]; then
|
||||
_body=$(cat)
|
||||
elif [ "''${1:-}" = "--body" ]; then
|
||||
_body="$2"
|
||||
if [ "''${1:-}" = "--body" ]; then
|
||||
_body="$2"; shift 2 || true
|
||||
elif [ "''${1:-}" = "-f" ]; then
|
||||
_body=$(cat "$2")
|
||||
_body=$(cat "$2"); shift 2 || true
|
||||
elif [ "''${1:-}" = "-" ]; then
|
||||
_body=$(cat); shift
|
||||
elif [[ "''${1:-}" == --* ]]; then
|
||||
echo "hive-forge comment: unknown flag '$1' (did you mean --body?)" >&2; exit 1
|
||||
elif [ ! -t 0 ]; then
|
||||
# Stdin is piped — use it for the body. Any trailing
|
||||
# positional is a repo override (the #379 trap).
|
||||
_body=$(cat)
|
||||
elif [ $# -eq 0 ]; then
|
||||
echo "hive-forge comment: no body — pass --body <text>, -f <file>, - (stdin), or a bare positional" >&2; exit 1
|
||||
else
|
||||
_body="$*"
|
||||
_body="$1"; shift
|
||||
fi
|
||||
# Any leftover positional (after the body source consumed its
|
||||
# args) is a repo override, same shape as comment-edit /
|
||||
# issue-edit / etc.
|
||||
if [ $# -gt 0 ]; then _repo="$1"; fi
|
||||
if [ -z "$(printf '%s' "$_body" | tr -d '[:space:]')" ]; then
|
||||
echo "hive-forge comment: refusing to post empty comment body" >&2; exit 1
|
||||
fi
|
||||
|
|
@ -167,23 +184,28 @@ pkgs.writeShellApplication {
|
|||
cmd_comment_edit() {
|
||||
# comment-edit <id> [--body <text> | -f <file> | -] [repo]
|
||||
# Edit an existing comment by its id.
|
||||
# Same precedence rules as `comment` (see #379): piped stdin
|
||||
# always wins over a bare positional, so the natural HEREDOC
|
||||
# form doesn't silently get its body replaced by the repo arg.
|
||||
if [ $# -lt 1 ]; then echo "usage: hive-forge comment-edit <id> [--body <text> | -f <file> | -] [repo]" >&2; exit 1; fi
|
||||
local _id="$1"; shift
|
||||
local _body _repo="$HIVE_FORGE_REPO"
|
||||
if [ $# -eq 0 ] || [ "''${1:-}" = "-" ]; then
|
||||
_body=$(cat)
|
||||
elif [ "''${1:-}" = "--body" ]; then
|
||||
if [ "''${1:-}" = "--body" ]; then
|
||||
_body="$2"; shift 2 || true
|
||||
if [ $# -gt 0 ]; then _repo="$1"; fi
|
||||
elif [ "''${1:-}" = "-f" ]; then
|
||||
_body=$(cat "$2"); shift 2 || true
|
||||
if [ $# -gt 0 ]; then _repo="$1"; fi
|
||||
elif [ "''${1:-}" = "-" ]; then
|
||||
_body=$(cat); shift
|
||||
elif [[ "''${1:-}" == --* ]]; then
|
||||
echo "hive-forge comment-edit: unknown flag '$1'" >&2; exit 1
|
||||
elif [ ! -t 0 ]; then
|
||||
_body=$(cat)
|
||||
elif [ $# -eq 0 ]; then
|
||||
echo "hive-forge comment-edit: no body — pass --body <text>, -f <file>, - (stdin), or a bare positional" >&2; exit 1
|
||||
else
|
||||
_body="$1"; shift
|
||||
if [ $# -gt 0 ]; then _repo="$1"; fi
|
||||
fi
|
||||
if [ $# -gt 0 ]; then _repo="$1"; fi
|
||||
if [ -z "$(printf '%s' "$_body" | tr -d '[:space:]')" ]; then
|
||||
echo "hive-forge comment-edit: refusing to post empty comment body" >&2; exit 1
|
||||
fi
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue