@@ -6,6 +6,7 @@ import { extractOperations } from "./parser/extractor.js";
66import { executeRequest } from "./executor/http.js" ;
77import { formatOutput } from "./output/formatters.js" ;
88import { registerAuthCommands } from "./auth/commands.js" ;
9+ import { resolveAuth as resolveAuthFromFlags } from "./auth/flags.js" ;
910import { registerInitCommand } from "./config/init.js" ;
1011import { registerUseCommand } from "./templates/commands.js" ;
1112import { loadConfig , resolveConfig } from "./config/rc.js" ;
@@ -59,13 +60,19 @@ async function main() {
5960 // Resolve spec: --spec flag > .toclirc config
6061 let specPath = getFlagValue ( rawArgs , "--spec" ) ;
6162 let configBaseUrl : string | undefined ;
63+ let rcAuthType : string | undefined ;
64+ let rcAuthToken : string | undefined ;
65+ let rcAuthEnvVar : string | undefined ;
6266
6367 if ( ! specPath ) {
6468 const rc = await loadConfig ( ) ;
6569 if ( rc ) {
6670 const resolved = resolveConfig ( rc , envName ) ;
6771 specPath = resolved . spec ;
6872 configBaseUrl = resolved . baseUrl ;
73+ rcAuthType = resolved . authType ;
74+ rcAuthToken = resolved . authToken ;
75+ rcAuthEnvVar = resolved . authEnvVar ;
6976 }
7077 }
7178
@@ -93,10 +100,22 @@ async function main() {
93100 return ;
94101 }
95102
103+ const auth = await resolveAuthFromFlags (
104+ {
105+ token : getFlagValue ( rawArgs , "--token" ) ,
106+ apiKey : getFlagValue ( rawArgs , "--api-key" ) ,
107+ profile : getFlagValue ( rawArgs , "--profile" ) ,
108+ rcAuthType,
109+ rcAuthToken,
110+ rcAuthEnvVar,
111+ } ,
112+ spec
113+ ) ;
114+
96115 const config : RuntimeConfig = {
97116 specPath,
98117 baseUrl : getFlagValue ( rawArgs , "--base-url" ) ?? configBaseUrl ?? resolveBaseUrl ( spec , specPath ) ,
99- auth : resolveAuth ( rawArgs ) ,
118+ auth,
100119 output : getFlagValue ( rawArgs , "--output" ) ?? ( process . stdout . isTTY ? "pretty" : "json" ) ,
101120 maxItems : getFlagValue ( rawArgs , "--max-items" ) ? parseInt ( getFlagValue ( rawArgs , "--max-items" ) ! ) : undefined ,
102121 verbose : rawArgs . includes ( "--verbose" ) ,
@@ -360,14 +379,6 @@ function simplifyName(operationId: string, tag: string): string {
360379 return operationId.toLowerCase();
361380}
362381
363- function resolveAuth(args: string[]): RuntimeConfig["auth"] {
364- const token = getFlagValue(args, "--token");
365- if (token) return { type: "bearer", value: token };
366- const apiKey = getFlagValue(args, "--api-key");
367- if (apiKey) return { type: "apiKey", value: apiKey, headerName: "X-API-Key" };
368- return { type: "none", value: "" };
369- }
370-
371382function getFlagValue(args: string[], flag: string): string | undefined {
372383 const idx = args.indexOf(flag);
373384 return idx !== -1 && idx + 1 < args.length ? args[idx + 1] : undefined;
0 commit comments