feat(muse-cli): streamlined account argument handling and extracted clean inner invocation wrapper
This commit is contained in:
@@ -14,11 +14,8 @@ NETVM_BIN="$(cd -P "$(dirname "$SCRIPT_SRC")" && pwd)"
|
||||
VALID_ACCOUNTS=("muse" "pip" "646" "opm" "def" "dev")
|
||||
|
||||
show_usage() {
|
||||
echo "Usage: muse --account <name> <command> [arguments...]"
|
||||
echo " muse -a <name> <command> [arguments...]"
|
||||
echo ""
|
||||
echo "Required:"
|
||||
echo " -a, --account <name> Target NetVM account / node identity"
|
||||
echo "Usage: muse <account> <command> [arguments...]"
|
||||
echo " muse -a <account> <command> [arguments...]"
|
||||
echo ""
|
||||
echo "Available accounts:"
|
||||
for acct in "${VALID_ACCOUNTS[@]}"; do
|
||||
@@ -42,6 +39,17 @@ show_usage() {
|
||||
ACCOUNT=""
|
||||
POSITIONAL=()
|
||||
|
||||
# Pre-check if first argument is a valid account name (e.g. 'muse 646 ...')
|
||||
if [[ $# -gt 0 ]]; then
|
||||
for acct in "${VALID_ACCOUNTS[@]}"; do
|
||||
if [[ "$1" == "$acct" ]]; then
|
||||
ACCOUNT="$1"
|
||||
shift
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
-a|--account)
|
||||
@@ -72,7 +80,7 @@ while [[ $# -gt 0 ]]; do
|
||||
done
|
||||
|
||||
if [[ -z "$ACCOUNT" ]]; then
|
||||
echo "Error: No account specified. Please specify an account with -a or --account." >&2
|
||||
echo "Error: No account specified. Specify account as first argument or with -a/--account." >&2
|
||||
echo ""
|
||||
show_usage
|
||||
exit 1
|
||||
|
||||
Executable
+20
@@ -0,0 +1,20 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
node = sys.argv[1]
|
||||
conf_dir = os.path.expanduser(f"~/.config/muse-cli/{node}")
|
||||
os.environ["MUSE_CONFIG_DIR"] = conf_dir
|
||||
|
||||
sys.path.insert(0, os.path.expanduser("~/.local/lib/python3.14/site-packages"))
|
||||
import muse_cli.cli as cli
|
||||
|
||||
cli.CONFIG_DIR = conf_dir
|
||||
cli.CONFIG_FILE = os.path.join(conf_dir, "config.json")
|
||||
cli.COOKIES_FILE = os.path.join(conf_dir, "cookies.txt")
|
||||
|
||||
sys.argv = [sys.argv[0]] + sys.argv[2:]
|
||||
|
||||
try:
|
||||
cli.main()
|
||||
except SystemExit as e:
|
||||
sys.exit(e.code)
|
||||
+1
-12
@@ -14,18 +14,7 @@ mkdir -p "$CONF_DIR"
|
||||
|
||||
run_cli() {
|
||||
export MUSE_CONFIG_DIR="$CONF_DIR"
|
||||
"$NETVM_BIN/netvm-exec.sh" "$NODE" -- python3 -c "
|
||||
import os, sys
|
||||
os.environ['MUSE_CONFIG_DIR'] = '$CONF_DIR'
|
||||
import muse_cli.cli as cli
|
||||
cli.CONFIG_DIR = '$CONF_DIR'
|
||||
cli.CONFIG_FILE = os.path.join('$CONF_DIR', 'config.json')
|
||||
cli.COOKIES_FILE = os.path.join('$CONF_DIR', 'cookies.txt')
|
||||
try:
|
||||
cli.main()
|
||||
except SystemExit as e:
|
||||
sys.exit(e.code)
|
||||
" "$@"
|
||||
"$NETVM_BIN/netvm-exec.sh" "$NODE" -- python3 "$NETVM_BIN/muse-cli-inner.py" "$NODE" "$@"
|
||||
}
|
||||
|
||||
# First attempt
|
||||
|
||||
Reference in New Issue
Block a user