#!/bin/sh
# cn-save — shorthand for `cn commit` + `cn push`.
#
# Package command for cnos.core (migrated from built-in in
# v3.37.0 per #184 command pipeline symmetry).
#
# Usage:
#   cn save                 commit (with empty message) then push
#   cn save "my message"    commit with message then push
#   cn save my message      joined commit message then push
#
# `commit` and `push` remain built-in for this cycle (explicit
# non-goal in #184) so this wrapper simply chains them via cn.
#
# Environment:
#   CN_HUB_PATH       exported by Cn_command.dispatch (used by cn
#                     commit + cn push internally)

set -eu

: "${CN_HUB_PATH:?cn-save: CN_HUB_PATH not set (expected via cn dispatch)}"

# Forward any args as the commit message. cn commit joins its
# remaining positional args into a single message string.
if [ $# -gt 0 ]; then
  cn commit "$@"
else
  cn commit
fi

cn push
