@tocca-systems/twp-cli 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.public.md +45 -0
- package/README.md +12 -1
- package/dist/ai-dispatch-AAV7BYPB.js +77 -0
- package/dist/{backlog-62DCJY45.js → backlog-D7PL5FLC.js} +17 -5
- package/dist/{chunk-U457A23B.js → chunk-EOFANBVM.js} +1 -1
- package/dist/{chunk-7ZVTACQS.js → chunk-JKSXUBND.js} +4 -3
- package/dist/{chunk-Y46OQT4N.js → chunk-MZHTRHZS.js} +3 -3
- package/dist/chunk-NAQ7OCUV.js +17 -0
- package/dist/chunk-O52CUEDO.js +6 -0
- package/dist/chunk-QQRJLH6B.js +3 -0
- package/dist/{chunk-6G3AJ4JZ.js → chunk-QVXZEUKN.js} +1 -1
- package/dist/cli.js +9 -5
- package/dist/{commands-HS3KIPJ4.js → commands-HYHUXQZT.js} +13 -13
- package/dist/{commands-QKNOQRWT.js → commands-YPT6RK74.js} +1 -1
- package/dist/run-TCAJZMNJ.js +63 -0
- package/dist/{task-EY3XJHST.js → task-ZYBI6Z4U.js} +50 -13
- package/package.json +1 -1
- package/dist/ai-dispatch-T6PJ4DUG.js +0 -82
- package/dist/chunk-4QI5NX4C.js +0 -6
- package/dist/run-2GFG6YVB.js +0 -57
package/dist/run-2GFG6YVB.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
|
-
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
-
import{stringWidth}from"./chunk-WVS4W5FY.js";import{GLOBAL_OPTIONS_HELP,HELP_TOKEN,splitFlagToken}from"./chunk-U457A23B.js";import{Resolver,requireDefaultProject}from"./chunk-Y46OQT4N.js";import{ApiError,TwpApiClient,appendQuery}from"./chunk-7ZVTACQS.js";import"./chunk-II5RVJQN.js";import{DEFAULT_MAX_ITEMS,DEFAULT_MAX_PAGES,nextPageNotes,positiveInteger,shellQuote}from"./chunk-2SGDY6YP.js";import{ApiResponseError,EXIT_API_CLIENT,EXIT_API_SERVER,EXIT_AUTH,EXIT_FAILURE,
|
|
4
|
-
EXIT_OK,EXIT_USAGE,NetworkError,UsageError}from"./chunk-M3GWY6NT.js";import{ResolveError}from"./chunk-5QCAIKFE.js";import{AuthSession,NotLoggedInError,SessionExpiredError,loadCredentials}from"./chunk-63LDNYGW.js";import{effectiveApiUrl,loadUserConfig,resolveConfiguredOutput,resolveProfile}from"./chunk-NERYSBA4.js";import"./chunk-RZVI6PMW.js";import{httpFetch}from"./chunk-J7QYPKVK.js";import{stripTerminalControls}from"./chunk-NHYMHCAT.js";import"./chunk-VSJBJXZO.js";var SENSITIVE_HEADERS=new Set(["authorization","proxy-authorization","cookie","set-cookie","x-api-key","x-auth-token","x-vercel-protection-bypass"]);var REDACTED="***\uFF08\u4F0F\u5B57\uFF09";var SECRET_KEY_PATTERN="[A-Za-z0-9_-]*(?:token|secret|password|passwd|api[_-]?key|credential)[A-Za-z0-9_-]*";function redactSecrets(text){return text.replace(/\bBearer\s+[^\s"'`,;)\]}]+/gi,`Bearer ${REDACTED}`).replace(new RegExp(`("${SECRET_KEY_PATTERN}"\\s*:\\s*)"(?:[^"\\\\]|\\\\.)*"`,"gi"),`$1"${REDACTED}\
|
|
5
|
-
"`).replace(new RegExp(`([?&]${SECRET_KEY_PATTERN}=)[^&\\s]+`,"gi"),`$1${REDACTED}`)}function formatHeaders(headers){if(!headers)return[];const entries=headers instanceof Headers?[...headers.entries()]:Array.isArray(headers)?headers:Object.entries(headers);return entries.map(([name,value])=>{const shown=SENSITIVE_HEADERS.has(name.toLowerCase())?REDACTED:redactSecrets(String(value));return` ${name.toLowerCase()}: ${shown}`})}var BODY_LIMIT=4e3;function formatBody(raw){const safe=stripTerminalControls(
|
|
6
|
-
redactSecrets(raw));return safe.length>BODY_LIMIT?`${safe.slice(0,BODY_LIMIT)}
|
|
7
|
-
\u2026\uFF08\u4EE5\u964D ${safe.length-BODY_LIMIT} \u6587\u5B57\u3092\u7701\u7565\uFF09`:safe}function withDebug(inner,options={}){const write=options.write??(text=>void process.stderr.write(text));const now=options.now??(()=>Date.now());return async(input,init)=>{const method=init?.method??"GET";const lines=[`[debug] \u2192 ${method} ${redactSecrets(input)}`,...formatHeaders(init?.headers)];if(typeof init?.body==="string")lines.push(` ${formatBody(init.body)}`);write(`${lines.join("\n")}
|
|
8
|
-
`);const started=now();let res;try{res=await inner(input,init)}catch(err){write(`[debug] \u2717 \u901A\u4FE1\u306B\u5931\u6557\u3057\u307E\u3057\u305F (${now()-started}ms): ${redactSecrets(err.message)}
|
|
9
|
-
`);throw err}const out=[`[debug] \u2190 ${res.status} ${res.statusText} (${now()-started}ms)`,...formatHeaders(res.headers)];const raw=await res.clone().text().catch(()=>"\uFF08\u672C\u6587\u3092\u8AAD\u3081\u307E\u305B\u3093\u3067\u3057\u305F\uFF09");if(raw!=="")out.push(` ${formatBody(raw)}`);write(`${out.join("\n")}
|
|
10
|
-
`);return res}}var OUTPUT_FORMATS=["json","table","text","tsv"];function isOutputFormat(value){return typeof value==="string"&&OUTPUT_FORMATS.includes(value)}function resolveOutputFormat(input){if(input.flag!==void 0){return isOutputFormat(input.flag)?input.flag:null}if(isOutputFormat(input.configured))return input.configured;return input.isTty?"table":"json"}function formatOutput(value,format){switch(format){case"json":return formatJson(value);case"table":return formatTable(value);case"text":return formatDelimited(
|
|
11
|
-
value," ");case"tsv":return formatDelimited(value," ")}}var JSON_UNSAFE_CONTROLS=/[\u007f-\u009f]/gu;function formatJson(value){const text=JSON.stringify(value===void 0?null:value,null,2);return text.replace(JSON_UNSAFE_CONTROLS,ch=>`\\u${ch.codePointAt(0)?.toString(16).padStart(4,"0")??""}`)}function cell(value){if(value===null||value===void 0)return"";if(typeof value==="string")return stripTerminalControls(value);if(typeof value==="number"||typeof value==="boolean"||typeof value==="bigint"){return String(
|
|
12
|
-
value)}return stripTerminalControls(JSON.stringify(value)??"")}function isPlainRecord(value){return typeof value==="object"&&value!==null&&!Array.isArray(value)}function collectColumns(rows){const columns=[];const seen=new Set;for(const row of rows){for(const key of Object.keys(row)){if(!seen.has(key)){seen.add(key);columns.push(key)}}}return columns}function renderRow(cells,widths){return cells.map((text,i)=>{if(i===cells.length-1)return text;const pad=Math.max(0,(widths[i]??0)-stringWidth(text));
|
|
13
|
-
return text+" ".repeat(pad)}).join(" ").trimEnd()}function singleLine(text){return stripTerminalControls(text).replace(/\t/g,"\\t").replace(/\n/g,"\\n")}function renderGrid(header,rows){const normalizedHeader=header?header.map(singleLine):null;const normalizedRows=rows.map(row=>row.map(singleLine));return renderGridNormalized(normalizedHeader,normalizedRows)}function renderGridNormalized(header,rows){const all=header?[header,...rows]:rows;const columnCount=all.reduce((max,row)=>Math.max(max,row.
|
|
14
|
-
length),0);const widths=[];for(let i=0;i<columnCount;i+=1){widths.push(all.reduce((max,row)=>Math.max(max,stringWidth(row[i]??"")),0))}const lines=[];if(header){lines.push(renderRow(header,widths));lines.push(widths.map(w=>"-".repeat(Math.max(1,w))).join(" ").trimEnd())}for(const row of rows)lines.push(renderRow(row,widths));return lines.join("\n")}function formatTable(value){if(Array.isArray(value)){if(value.length===0)return"";const records=value.filter(isPlainRecord);if(records.length!==value.
|
|
15
|
-
length){return renderGrid(null,value.map(v=>[cell(v)]))}const columns=collectColumns(records);if(columns.length===0)return"";return renderGrid(columns,records.map(row=>columns.map(c=>cell(row[c]))))}if(isPlainRecord(value)){const entries=Object.entries(value);if(entries.length===0)return"";return renderGrid(null,entries.map(([k,v])=>[k,cell(v)]))}return cell(value)}function escapeDelimited(text){return text.replace(/\\/g,"\\\\").replace(/\t/g,"\\t").replace(/\r/g,"\\r").replace(/\n/g,"\\n")}function formatDelimited(value,separator){
|
|
16
|
-
const rows=[];if(Array.isArray(value)){const records=value.filter(isPlainRecord);if(value.length>0&&records.length===value.length){const columns=collectColumns(records);for(const row of records)rows.push(columns.map(c=>cell(row[c])))}else{for(const v of value)rows.push([cell(v)])}}else if(isPlainRecord(value)){rows.push(Object.values(value).map(cell))}else{rows.push([cell(value)])}return rows.map(row=>row.map(escapeDelimited).join(separator)).join("\n")}async function evaluateQuery(expression,value){if(expression.trim()===""){throw new UsageError("--query \u306B\u7A7A\u306E\u5F0F\u306F\u6307\u5B9A\u3067\u304D\u307E\u305B\u3093")}const{search}=await import("./dist-HZIZTJ4O.js");try{return search(value??null,expression)}catch(err){throw new UsageError(`--query \u306E\u5F0F\u3092\u8A55\u4FA1\u3067\u304D\u307E\u305B\u3093: ${err.message}`)}}function alignedList(entries,indent=" "){const width=entries.reduce((max,[left])=>Math.max(max,stringWidth(left)),0);return entries.map(([left,right])=>`${indent}${left}${" ".repeat(Math.max(0,width-stringWidth(left)))} ${right}`).join("\n")}function subresourcesOf(resource){return resource.subresources??[]}function renderResourceHelp(resource,path){const subresources=subresourcesOf(resource);const operationSection=resource.operations.length===0?"":`
|
|
17
|
-
\u64CD\u4F5C:
|
|
18
|
-
${alignedList(resource.operations.map(op=>[op.name,op.summary]))}
|
|
19
|
-
`;const subSection=subresources.length===0?"":`
|
|
20
|
-
\u30B5\u30D6\u8CC7\u6E90:
|
|
21
|
-
${alignedList(subresources.map(sub=>[`${sub.name} <\u64CD\u4F5C>`,sub.summary]))}
|
|
22
|
-
`;return`twp ${path} \u2014 ${resource.summary}
|
|
23
|
-
|
|
24
|
-
\u4F7F\u3044\u65B9:
|
|
25
|
-
twp ${path} <\u64CD\u4F5C> [\u5F15\u6570] [\u30AA\u30D7\u30B7\u30E7\u30F3]
|
|
26
|
-
twp ${path} <\u64CD\u4F5C> ${HELP_TOKEN} \u305D\u306E\u64CD\u4F5C\u306E\u8A73\u3057\u3044\u30D8\u30EB\u30D7
|
|
27
|
-
${operationSection}${subSection}
|
|
28
|
-
${GLOBAL_OPTIONS_HELP}
|
|
29
|
-
`}function renderOperationHelp(op,path){const sections=[`twp ${path} ${op.name} \u2014 ${op.summary}`,"","\u4F7F\u3044\u65B9:",` ${op.usage}`];if(op.description!==void 0){sections.push("",...op.description.split("\n"))}if(op.destructive===true){sections.push("","\u26A0 \u7834\u58CA\u7684\u306A\u64CD\u4F5C\u3067\u3059\u3002\u5B9F\u884C\u3059\u308B\u306B\u306F --yes \u304C\u5FC5\u8981\u3067\u3059\u3002")}if(op.flags.length>0){sections.push("","\u30AA\u30D7\u30B7\u30E7\u30F3:",alignedList(op.flags.
|
|
30
|
-
map(flag=>[flag.takesValue?`${flag.name} ${flag.placeholder??"<\u5024>"}`:flag.name,flag.summary])))}sections.push("",GLOBAL_OPTIONS_HELP,"");return sections.join("\n")}function renderUnknownOperation(resource,path,attempted){const names=[...resource.operations.map(op=>op.name),...subresourcesOf(resource).map(sub=>`${sub.name} <\u64CD\u4F5C>`)].join(" / ");return attempted===void 0?`twp ${path} \u306B\u306F\u64CD\u4F5C\u306E\u6307\u5B9A\u304C\u5FC5\u8981\u3067\u3059\uFF08${names}\uFF09\u3002\u8A73\u3057\u304F\u306F twp ${path}\
|
|
31
|
-
${HELP_TOKEN}`:`twp ${path} \u306B\u300C${attempted}\u300D\u3068\u3044\u3046\u64CD\u4F5C\u306F\u3042\u308A\u307E\u305B\u3093\uFF08${names}\uFF09\u3002\u8A73\u3057\u304F\u306F twp ${path} ${HELP_TOKEN}`}function parseOperationArgs(argv,specs){const byName=new Map(specs.map(spec=>[spec.name,spec]));const args=[];const flags=new Map;let positionalOnly=false;for(let i=0;i<argv.length;i+=1){const arg=argv[i];if(arg===void 0)continue;if(!positionalOnly&&arg==="--"){positionalOnly=true;continue}if(positionalOnly||!arg.startsWith("-")||arg==="-"){args.push(arg);continue}const{name,value:inline}=splitFlagToken(arg);const spec=byName.get(name);if(spec===void 0){const shortEquals=!arg.startsWith("--")&&arg.
|
|
32
|
-
includes("=");throw new UsageError(`\u4E0D\u660E\u306A\u30AA\u30D7\u30B7\u30E7\u30F3: ${arg}`,shortEquals?`\u77ED\u3044\u30D5\u30E9\u30B0\u306B = \u306F\u4F7F\u3048\u307E\u305B\u3093\u3002\u7A7A\u767D\u3067\u533A\u5207\u3063\u3066\u304F\u3060\u3055\u3044: ${arg.replace("="," ")}`:void 0)}if(flags.has(name))throw new UsageError(`${name} \u304C\u8907\u6570\u56DE\u6307\u5B9A\u3055\u308C\u3066\u3044\u307E\u3059`);if(!spec.takesValue){if(inline!==void 0){throw new UsageError(`${name} \u306F\u5024\u3092\u53D6\u308A\u307E\u305B\u3093`,
|
|
33
|
-
`${name} \u306F\u6307\u5B9A\u306E\u6709\u7121\u3060\u3051\u304C\u610F\u5473\u3092\u6301\u3061\u307E\u3059\u3002`)}flags.set(name,"");continue}if(inline!==void 0){flags.set(name,inline);continue}const next=argv[i+1];if(next===void 0||next.startsWith("-")&&next!=="-"){throw new UsageError(`${name} \u306B\u306F\u5024\u304C\u5FC5\u8981\u3067\u3059`,`\`-\` \u3067\u59CB\u307E\u308B\u5024\u306F ${name}=\u5024 \u306E\u5F62\u3067\u6E21\u305B\u307E\u3059\u3002`)}flags.set(name,next);i+=1}return{args,flags}}var LOADERS={backlog:async()=>(await import("./backlog-62DCJY45.js")).backlogDomain,project:async()=>(await import("./project-KIPSH5GP.js")).projectDomain,task:async()=>(await import("./task-EY3XJHST.js")).taskDomain};async function loadDomain(name){return LOADERS[name]()}var writeOut=text=>void process.stdout.write(text);var writeErr=text=>void process.stderr.write(text);function line(text){return text===""?"":text.endsWith("\n")?text:`${text}
|
|
34
|
-
`}function outputValue(operation,format,body){return format==="json"?operation.raw(body):operation.summarize(body)}function requiresYes(operation,yes){return operation.destructive===true&&!yes}function exitCodeFor(err){if(err instanceof UsageError)return EXIT_USAGE;if(err instanceof NotLoggedInError||err instanceof SessionExpiredError)return EXIT_AUTH;if(err instanceof ApiError){if(err.status===401)return EXIT_AUTH;if(err.status>=400&&err.status<500)return EXIT_API_CLIENT;return EXIT_API_SERVER}
|
|
35
|
-
if(err instanceof ApiResponseError||err instanceof NetworkError)return EXIT_API_SERVER;if(err instanceof ResolveError){if(err.status===401)return EXIT_AUTH;if(err.status!==null&&err.status>=400&&err.status<500)return EXIT_API_CLIENT;return EXIT_API_SERVER}return EXIT_FAILURE}function reportError(err,format,code){const message=stripTerminalControls(err instanceof Error?err.message:String(err));const rawHint=err instanceof UsageError?err.hint:void 0;const hint=rawHint!==void 0?stripTerminalControls(
|
|
36
|
-
rawHint):void 0;if(format==="json"){const body={code,message};if(err instanceof ApiError)body["status"]=err.status;if(err instanceof ResolveError&&err.status!==null)body["status"]=err.status;if(hint!==void 0)body["hint"]=hint;writeErr(`${JSON.stringify({error:body},null,2)}
|
|
37
|
-
`);return}writeErr(`${message}
|
|
38
|
-
`);if(hint!==void 0)writeErr(`${hint}
|
|
39
|
-
`)}function dryRunValue(apiUrl,plan){const value={method:plan.method,url:`${apiUrl}${appendQuery(plan.path,plan.query)}`};if(plan.body!==void 0)value["body"]=plan.body;return value}async function send(client,apiUrl,plan){try{return await client.request(plan.method,appendQuery(plan.path,plan.query),plan.body)}catch(err){if(err instanceof ApiError||err instanceof NotLoggedInError||err instanceof SessionExpiredError){throw err}throw new NetworkError(`${apiUrl} \u3078\u306E\u901A\u4FE1\u306B\u5931\u6557\u3057\u307E\u3057\u305F: ${err.
|
|
40
|
-
message}`,{cause:err})}}function capExceeded(reason,pages,count,cursor){return new UsageError(`--all \u304C\u4E0A\u9650\u306B\u9054\u3057\u305F\u305F\u3081\u4E2D\u65AD\u3057\u307E\u3057\u305F\uFF08${reason}\uFF0F${pages} \u30DA\u30FC\u30B8\u30FB${count} \u4EF6\u3092\u53D6\u5F97\u6E08\u307F\uFF09\u3002\u3053\u308C\u306F\u5168\u4EF6\u3067\u306F\u3042\u308A\u307E\u305B\u3093\u3002`,`--limit \u3092\u5927\u304D\u304F\u3057\u3066\u5F80\u5FA9\u3092\u6E1B\u3089\u3059\u304B\u3001--max-pages / --max-items \u3092\u4E0A\u3052\u3066\u304F\u3060\u3055\u3044\u3002\u7D9A\u304D\u3060\u3051\u3092\u53D6\u308B\u306A\u3089 --cursor ${shellQuote(
|
|
41
|
-
cursor)} \u304B\u3089\u518D\u958B\u3067\u304D\u307E\u3059`)}async function fetchAllPages(args){const{paging,maxPages,maxItems}=args;const merged=[];const first=args.plan.query?.[paging.cursorParam];let sent=typeof first==="string"?first:"";for(let page=1;;page+=1){const plan=page===1?args.plan:{...args.plan,query:{...args.plan.query,[paging.cursorParam]:sent}};let body;try{body=await send(args.client,args.apiUrl,plan)}catch(err){if(page>1){writeErr(`--all \u306F ${page} \u30DA\u30FC\u30B8\u76EE\u3067\u5931\u6557\u3057\u307E\u3057\u305F\uFF08${page-
|
|
42
|
-
1} \u30DA\u30FC\u30B8\u30FB${merged.length} \u4EF6\u3092\u53D6\u5F97\u6E08\u307F\uFF09\u3002\u3053\u308C\u306F\u5168\u4EF6\u3067\u306F\u3042\u308A\u307E\u305B\u3093\u3002\u7D9A\u304D\u306F --cursor ${shellQuote(stripTerminalControls(sent))} \u304B\u3089\u518D\u958B\u3067\u304D\u307E\u3059\u3002
|
|
43
|
-
`)}throw err}for(const item of paging.items(body))merged.push(item);const next=paging.nextCursor(body);if(next===null)return{body:paging.withItems(body,merged),pages:page,count:merged.length};if(merged.length>=maxItems)throw capExceeded(`\u6700\u5927\u4EF6\u6570 ${maxItems} \u4EF6`,page,merged.length,next);if(page>=maxPages)throw capExceeded(`\u6700\u5927\u30DA\u30FC\u30B8\u6570 ${maxPages}`,page,merged.length,next);if(next===sent){throw new ApiResponseError(`\u540C\u3058\u30AB\u30FC\u30BD\u30EB\uFF08${next}\
|
|
44
|
-
\uFF09\u304C\u7E70\u308A\u8FD4\u3057\u8FD4\u3055\u308C\u305F\u305F\u3081\u4E2D\u65AD\u3057\u307E\u3057\u305F\u3002${merged.length} \u4EF6\u3092\u53D6\u5F97\u3057\u305F\u6642\u70B9\u3067\u3001\u3053\u308C\u306F\u5168\u4EF6\u3067\u306F\u3042\u308A\u307E\u305B\u3093\u3002`)}sent=next}}function resolvePaging(operation,path,input){const all=input.flags.has("--all");const maxPages=positiveInteger(input.flags,"--max-pages")??DEFAULT_MAX_PAGES;const maxItems=positiveInteger(input.flags,"--max-items")??DEFAULT_MAX_ITEMS;
|
|
45
|
-
positiveInteger(input.flags,"--limit");if(all&&operation.paging===void 0){throw new UsageError(`twp ${path} ${operation.name} \u306F --all \u306B\u5BFE\u5FDC\u3057\u3066\u3044\u307E\u305B\u3093`)}for(const name of["--max-pages","--max-items"]){if(!all&&input.flags.has(name)){throw new UsageError(`${name} \u306F --all \u3068\u4F75\u305B\u3066\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044`,`${name} \u3060\u3051\u3067\u306F\u4F55\u3082\u5909\u308F\u308A\u307E\u305B\u3093`)}}return{all,maxPages,maxItems}}
|
|
46
|
-
function profileAliases(profileName){const aliases=loadUserConfig().profiles?.[profileName]?.aliases;return aliases!==void 0?{aliases}:{}}function buildPrepareContext(args){const cache=new Map;return{resolver:args.resolver,projectId(explicit){if(explicit!==void 0&&explicit.trim()===""){throw new UsageError("--project \u306B\u7A7A\u306E\u5024\u306F\u6307\u5B9A\u3067\u304D\u307E\u305B\u3093","--project <\u30B3\u30FC\u30C9|ID> \u3092\u6307\u5B9A\u3059\u308B\u304B\u3001--project \u3054\u3068\u5916\u3057\u3066\u304F\u3060\u3055\u3044\u3002")}
|
|
47
|
-
const ref=requireDefaultProject(explicit,args.profileName,args.env,args.cwd).ref;const hit=cache.get(ref);if(hit!==void 0)return hit;const resolved=args.resolver.project(ref).then(project=>project.id);cache.set(ref,resolved);return resolved}}}async function runDomain(options){const{globals}=options;let format=null;try{const profile=resolveProfile(globals.profile);format=resolveOutputFormat({...globals.output!==void 0?{flag:globals.output}:{},...(()=>{const configured=resolveConfiguredOutput(profile.
|
|
48
|
-
name);return configured!==void 0?{configured}:{}})(),isTty:process.stdout.isTTY===true});if(format===null){throw new UsageError(`--output \u306B\u300C${globals.output??""}\u300D\u306F\u6307\u5B9A\u3067\u304D\u307E\u305B\u3093`,`\u6307\u5B9A\u3067\u304D\u308B\u306E\u306F ${OUTPUT_FORMATS.join(" / ")} \u3067\u3059`)}const domain=await loadDomain(options.domain);if(options.operation===HELP_TOKEN||options.help&&options.operation===void 0){const[extra,...rest2]=options.argv;if(extra===void 0){writeOut(
|
|
49
|
-
renderResourceHelp(domain,domain.name));return EXIT_OK}const target=domain.subresources?.find(resource2=>resource2.name===extra);if(target===void 0||rest2.length>0){throw new UsageError(renderUnknownOperation(domain,domain.name,extra))}writeOut(renderResourceHelp(target,`${domain.name} ${extra}`));return EXIT_OK}const sub=domain.subresources?.find(resource2=>resource2.name===options.operation);const resource=sub??domain;const path=sub===void 0?domain.name:`${domain.name} ${sub.name}`;const operationName=sub===
|
|
50
|
-
void 0?options.operation:options.argv[0];const rest=sub===void 0?options.argv:options.argv.slice(1);if(sub!==void 0&&(operationName===HELP_TOKEN||options.help&&operationName===void 0)){writeOut(renderResourceHelp(sub,path));return EXIT_OK}const operation=resource.operations.find(op=>op.name===operationName);if(operation===void 0){throw new UsageError(renderUnknownOperation(resource,path,operationName))}if(options.help||rest[0]===HELP_TOKEN){writeOut(renderOperationHelp(operation,path));return EXIT_OK}
|
|
51
|
-
const input=parseOperationArgs(rest,operation.flags);if(!globals.dryRun&&requiresYes(operation,globals.yes)){throw new UsageError(`twp ${path} ${operation.name} \u306F\u7834\u58CA\u7684\u306A\u64CD\u4F5C\u3067\u3059\u3002\u5B9F\u884C\u3059\u308B\u306B\u306F --yes \u3092\u4ED8\u3051\u3066\u304F\u3060\u3055\u3044\u3002`)}const paging=resolvePaging(operation,path,input);const stored=loadCredentials(profile.name);const apiUrl=effectiveApiUrl(profile,stored?.api_url);const transport=options.fetchImpl??
|
|
52
|
-
httpFetch;const fetchImpl=globals.debug?withDebug(transport):transport;const session=new AuthSession(profile.name,apiUrl,process.env,fetchImpl);const client=new TwpApiClient(apiUrl,session,fetchImpl,options.version);const prepared=operation.prepare===void 0?input:await operation.prepare(input,buildPrepareContext({resolver:new Resolver(client,{profile:profile.name,refresh:globals.refresh,...profileAliases(profile.name)}),profileName:profile.name,env:process.env,cwd:process.cwd()}));const plan=operation.
|
|
53
|
-
plan(prepared);for(const note of operation.plannedNotes?.(prepared)??[])writeErr(`${stripTerminalControls(note)}
|
|
54
|
-
`);if(globals.dryRun){writeOut(line(redactSecrets(formatOutput(dryRunValue(apiUrl,plan),format))));return EXIT_OK}let body;let paged;if(paging.all&&operation.paging!==void 0){paged=await fetchAllPages({client,apiUrl,plan,paging:operation.paging,maxPages:paging.maxPages,maxItems:paging.maxItems});body=paged.body}else{body=await send(client,apiUrl,plan)}const value=globals.query!==void 0?await evaluateQuery(globals.query,operation.raw(body)):outputValue(operation,format,body);writeOut(line(formatOutput(
|
|
55
|
-
value,format)));if(paged!==void 0){writeErr(`--all: ${paged.pages} \u30DA\u30FC\u30B8\u3092\u8FBF\u3063\u3066 ${paged.count} \u4EF6\u3092\u53D6\u5F97\u3057\u307E\u3057\u305F\u3002
|
|
56
|
-
`)}const pagingNotes=operation.paging===void 0?[]:nextPageNotes(body,prepared,{command:`twp ${path} ${operation.name}`,flags:operation.flags,profile:globals.profile});for(const note of[...pagingNotes,...operation.notes?.(body,prepared)??[]]){writeErr(`${stripTerminalControls(note)}
|
|
57
|
-
`)}return EXIT_OK}catch(err){const code=exitCodeFor(err);reportError(err,format,code);return code}}export{buildPrepareContext,exitCodeFor,fetchAllPages,outputValue,requiresYes,resolvePaging,runDomain};
|