(args, commandData)
| 76 | } |
| 77 | |
| 78 | export function mapArgumentsToOptions(args, commandData) { |
| 79 | const options = {}; |
| 80 | let subcommandName = null; |
| 81 | let subcommandGroupName = null; |
| 82 | |
| 83 | const cmdData = commandData.toJSON ? commandData.toJSON() : commandData; |
| 84 | |
| 85 | if (!cmdData || !cmdData.options) { |
| 86 | |
| 87 | return { |
| 88 | _positional: args, |
| 89 | get: (name) => args[0] || null, |
| 90 | getString: (name) => args[0] || null, |
| 91 | getUser: (name) => null, |
| 92 | getInteger: (name) => parseInt(args[0]) || null, |
| 93 | getBoolean: (name) => args[0] === 'true', |
| 94 | getSubcommand: () => null, |
| 95 | getSubcommandGroup: () => null, |
| 96 | validateRequired: () => ({ valid: true, missing: [] }) |
| 97 | }; |
| 98 | } |
| 99 | |
| 100 | const subcommandGroup = cmdData.options.find((opt) => opt.type === 2); |
| 101 | const subcommands = cmdData.options.filter((opt) => opt.type === 1); |
| 102 | const hasSubcommands = subcommands.length > 0 && !subcommandGroup; |
| 103 | |
| 104 | let currentArgs = args; |
| 105 | let optionDefs = []; |
| 106 | |
| 107 | logger.debug( |
| 108 | `Parsing prefix command: commandName=${cmdData.name}, args=${JSON.stringify(args)}, hasSubcommands=${hasSubcommands}, hasSubcommandGroup=${!!subcommandGroup}, optionsCount=${cmdData.options.length}`, |
| 109 | ); |
| 110 | |
| 111 | if (subcommandGroup) { |
| 112 | if (args.length > 0) { |
| 113 | subcommandGroupName = args[0].toLowerCase(); |
| 114 | const group = subcommandGroup.options?.find((g) => g.name === subcommandGroupName); |
| 115 | if (group && args.length > 1) { |
| 116 | subcommandName = resolveSubcommandAlias(args[1]); |
| 117 | const sub = group.options?.find((s) => s.name === subcommandName); |
| 118 | if (sub) { |
| 119 | optionDefs = sub.options?.filter((opt) => opt.type !== 1 && opt.type !== 2) || []; |
| 120 | currentArgs = args.slice(2); |
| 121 | } else { |
| 122 | logger.debug(`Subcommand ${subcommandName} not found in group ${subcommandGroupName}`); |
| 123 | } |
| 124 | } else if (!group) { |
| 125 | logger.debug(`Subcommand group ${subcommandGroupName} not found`); |
| 126 | } |
| 127 | } |
| 128 | } else if (hasSubcommands) { |
| 129 | if (args.length > 0) { |
| 130 | const resolvedSubcommand = resolveSubcommandAlias(args[0]); |
| 131 | logger.debug( |
| 132 | `Looking for subcommand: ${resolvedSubcommand}, available: ${subcommands.map((s) => s.name).join(', ')}`, |
| 133 | ); |
| 134 | const sub = subcommands.find((s) => s.name === resolvedSubcommand); |
| 135 | if (sub) { |
no test coverage detected