diff --git a/nix/packages/hive-forge-tools.nix b/nix/packages/hive-forge-tools.nix index 33eb6e5..84c3c37 100644 --- a/nix/packages/hive-forge-tools.nix +++ b/nix/packages/hive-forge-tools.nix @@ -137,24 +137,41 @@ pkgs.writeShellApplication { } cmd_comment() { - # comment [--body | -f | -] + # comment [--body | -f | -] [repo] # Post a comment on an issue or PR. - # Accepts --body (consistent with issue-create/pr-create), - # -f , - (stdin), or a bare positional body string. - if [ $# -lt 1 ]; then echo "usage: hive-forge comment [--body | -f | -]" >&2; exit 1; fi + # Body sources, in priority order: + # --body | -f | - (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 < [--body | -f | -] [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 , -f , - (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 [--body | -f | -] [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 [--body | -f | -] [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 , -f , - (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