@@ -26,6 +26,7 @@ import * as Stdio from "../../Stdio.ts"
2626import * as Terminal from "../../Terminal.ts"
2727import type { Contravariant , Covariant , NoInfer , Simplify } from "../../Types.ts"
2828import type { ChildProcessSpawner } from "../process/ChildProcessSpawner.ts"
29+ import * as CliConfig from "./CliConfig.ts"
2930import * as CliError from "./CliError.ts"
3031import * as CliOutput from "./CliOutput.ts"
3132import * as GlobalFlag from "./GlobalFlag.ts"
@@ -1412,8 +1413,9 @@ const showHelp = <Name extends string, Input, E, R, ContextInput>(
14121413 error : CliError . ShowHelp
14131414) : Effect . Effect < void , CliError . CliError , Environment > =>
14141415 Effect . gen ( function * ( ) {
1416+ const { builtIns } = yield * CliConfig . CliConfig
14151417 const formatter = yield * CliOutput . Formatter
1416- const helpDoc = yield * getHelpForCommandPath ( command , error . commandPath , GlobalFlag . BuiltIns )
1418+ const helpDoc = yield * getHelpForCommandPath ( command , error . commandPath , builtIns )
14171419 yield * Console . log ( formatter . formatHelpDoc ( helpDoc ) )
14181420 if ( error . errors . length > 0 ) {
14191421 yield * Console . error ( formatter . formatErrors ( error . errors as any ) )
@@ -1530,10 +1532,11 @@ export const runWith = <const Name extends string, Input, E, R, ContextInput>(
15301532 const commandImpl = toImpl ( command )
15311533 return Effect . fnUntraced (
15321534 function * ( args : ReadonlyArray < string > ) {
1535+ const { builtIns } = yield * CliConfig . CliConfig
15331536 const { tokens, trailingOperands } = Lexer . lex ( args )
15341537
15351538 // 1. Collect known global flags from the command tree
1536- const allFlags = getGlobalFlagsForCommandTree ( command , GlobalFlag . BuiltIns )
1539+ const allFlags = getGlobalFlagsForCommandTree ( command , builtIns )
15371540
15381541 // 2. Extract global flag tokens
15391542 const allFlagParams = allFlags . flatMap ( ( f ) => Param . extractSingleParams ( f . flag ) )
@@ -1548,8 +1551,8 @@ export const runWith = <const Name extends string, Input, E, R, ContextInput>(
15481551 // 3. Parse command arguments from remaining tokens
15491552 const parsedArgs = yield * Parser . parseArgs ( { tokens : remainder , trailingOperands } , command )
15501553 const commandPath = [ command . name , ...Parser . getCommandPath ( parsedArgs ) ] as const
1551- const handlerCtx : GlobalFlag . HandlerContext = { command, commandPath, version : config . version }
1552- const activeFlags = getGlobalFlagsForCommandPath ( command , commandPath , GlobalFlag . BuiltIns )
1554+ const handlerCtx : GlobalFlag . HandlerContext = { builtIns , command, commandPath, version : config . version }
1555+ const activeFlags = getGlobalFlagsForCommandPath ( command , commandPath , builtIns )
15531556
15541557 // 4. Reject globals that were passed outside the active command scope
15551558 const outOfScopeErrors = getOutOfScopeGlobalFlagErrors ( allFlags , activeFlags , flagMap , commandPath )
@@ -1589,7 +1592,9 @@ export const runWith = <const Name extends string, Input, E, R, ContextInput>(
15891592
15901593 // 7. Provide setting values
15911594 let program = commandImpl . handle ( parseResult . success , [ command . name ] )
1592- const [ , logLevel ] = yield * GlobalFlag . LogLevel . flag . parse ( emptyArgs )
1595+ const logLevel = activeFlags . includes ( GlobalFlag . LogLevel )
1596+ ? ( yield * GlobalFlag . LogLevel . flag . parse ( emptyArgs ) ) [ 1 ]
1597+ : Option . none ( )
15931598 program = Effect . provideService ( program , GlobalFlag . LogLevel , logLevel )
15941599 for ( const flag of activeFlags ) {
15951600 if ( flag . _tag !== "Setting" || flag === GlobalFlag . LogLevel ) continue
0 commit comments