feat: add --dry-run flag to all 47 CLI tools
When --dry-run is passed, each CLI prints the HTTP request it would make (method, URL, headers, body) without actually calling fetch(). Auth credentials are masked as "***" in the output. Useful for verifying request shape and API endpoints without needing real API keys or making actual API calls. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -16,6 +16,9 @@ async function api(method, path, body) {
|
||||
if (body && method !== 'GET') {
|
||||
headers['Content-Type'] = 'application/x-www-form-urlencoded'
|
||||
}
|
||||
if (args['dry-run']) {
|
||||
return { _dry_run: true, method, url: `${BASE_URL}${path}`, headers: { ...headers, 'Authorization': '***' }, body: body || undefined }
|
||||
}
|
||||
const res = await fetch(`${BASE_URL}${path}`, {
|
||||
method,
|
||||
headers,
|
||||
@@ -30,6 +33,9 @@ async function api(method, path, body) {
|
||||
}
|
||||
|
||||
async function apiJson(method, path, body) {
|
||||
if (args['dry-run']) {
|
||||
return { _dry_run: true, method, url: `${BASE_URL}${path}`, headers: { 'Authorization': '***', 'Content-Type': 'application/json', 'Accept': 'application/json' }, body: body || undefined }
|
||||
}
|
||||
const res = await fetch(`${BASE_URL}${path}`, {
|
||||
method,
|
||||
headers: {
|
||||
@@ -155,6 +161,10 @@ async function main() {
|
||||
if (args.now) formBody.append('now', 'true')
|
||||
if (args.top) formBody.append('top', 'true')
|
||||
if (args.shorten) formBody.append('shorten', 'true')
|
||||
if (args['dry-run']) {
|
||||
result = { _dry_run: true, method: 'POST', url: `${BASE_URL}/updates/create.json`, headers: { 'Authorization': '***', 'Content-Type': 'application/x-www-form-urlencoded', 'Accept': 'application/json' }, body: formBody.toString() }
|
||||
break
|
||||
}
|
||||
const res = await fetch(`${BASE_URL}/updates/create.json`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
@@ -197,6 +207,10 @@ async function main() {
|
||||
if (!order) { result = { error: '--order required (comma-separated update IDs)' }; break }
|
||||
const formBody = new URLSearchParams()
|
||||
order.split(',').forEach(uid => formBody.append('order[]', uid.trim()))
|
||||
if (args['dry-run']) {
|
||||
result = { _dry_run: true, method: 'POST', url: `${BASE_URL}/profiles/${id}/updates/reorder.json`, headers: { 'Authorization': '***', 'Content-Type': 'application/x-www-form-urlencoded', 'Accept': 'application/json' }, body: formBody.toString() }
|
||||
break
|
||||
}
|
||||
const res = await fetch(`${BASE_URL}/profiles/${id}/updates/reorder.json`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
|
||||
Reference in New Issue
Block a user