cf-cli-tools/cf-api
feibisi 1be3d8ef8d 初始提交:Cloudflare CLI 工具集
debian 开发,modiqi 修复 cf_load_profile 缺失问题。
9 个命令:cf-api/cf-zone/cf-dns/cf-cache/cf-ssl/cf-fw/cf-pagerule/cf-analytics/cf-hostname
支持多账号、域名自动解析 zone_id。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-24 02:39:31 +08:00

32 lines
920 B
Bash
Executable file
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
set -euo pipefail
# cf-api — Cloudflare REST API 底层调用器
# 用法: cf-api <METHOD> <endpoint> [curl-args...]
# 示例: cf-api GET /zones
# cf-api GET /zones/ZONE_ID/dns_records
# cf-api POST /zones/ZONE_ID/dns_records -d '{"type":"A","name":"test","content":"1.2.3.4"}'
# 选项: -p <profile> 指定配置 profile默认 default
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
source "$SCRIPT_DIR/cf-lib.sh"
cf_parse_profile "$@"
set -- "${CF_REMAINING_ARGS[@]}"
if [[ $# -lt 2 ]]; then
cat >&2 <<'EOF'
用法: cf-api <METHOD> <endpoint> [curl-args...]
示例:
cf-api GET /zones
cf-api GET /zones/ZONE_ID/dns_records
cf-api POST /zones/ZONE_ID/purge_cache -d '{"purge_everything":true}'
cf-api -p support GET /zones # 使用 support profile
EOF
exit 1
fi
cf_load_profile
METHOD="$1" ENDPOINT="$2"
shift 2
cf_call "$METHOD" "$ENDPOINT" "$@" | cf_pretty