|
| 1 | +/* |
| 2 | + * Copyright 2025 Adobe Inc. All rights reserved. |
| 3 | + * This file is licensed to you under the Apache License, Version 2.0 (the "License"); |
| 4 | + * you may not use this file except in compliance with the License. You may obtain a copy |
| 5 | + * of the License at http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | + * |
| 7 | + * Unless required by applicable law or agreed to in writing, software distributed under |
| 8 | + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS |
| 9 | + * OF ANY KIND, either express or implied. See the License for the specific language |
| 10 | + * governing permissions and limitations under the License. |
| 11 | + */ |
| 12 | + |
| 13 | +const { Help } = require('@oclif/core') |
| 14 | + |
| 15 | +/** |
| 16 | + * Custom Help class to handle alias resolution for command help display. |
| 17 | + * |
| 18 | + * Issue: When users run "aio rt --help", oclif's help system doesn't recognize |
| 19 | + * that "rt" is an alias for "runtime" and should display all subcommands. |
| 20 | + * The help system looks for "rt:*" subcommands which don't exist in the manifest |
| 21 | + * (they're registered as "runtime:*"). |
| 22 | + * |
| 23 | + * Solution: Override showHelp to resolve aliases to their canonical command names |
| 24 | + * before displaying help, ensuring proper subcommand listing. |
| 25 | + * |
| 26 | + * @see https://github.com/adobe/aio-cli-plugin-runtime |
| 27 | + */ |
| 28 | +class CustomHelp extends Help { |
| 29 | + /** |
| 30 | + * Show help for a command, resolving aliases to canonical names. |
| 31 | + * |
| 32 | + * @param {string[]} args - Command ID and arguments to show help for |
| 33 | + * @returns {Promise<void>} |
| 34 | + */ |
| 35 | + async showHelp (args) { |
| 36 | + // Skip alias resolution if args is invalid or empty |
| 37 | + if (!Array.isArray(args) || args.length === 0) { |
| 38 | + return super.showHelp(args) |
| 39 | + } |
| 40 | + |
| 41 | + // Map of known aliases to canonical command names |
| 42 | + // Add more mappings here as needed for other top-level aliases |
| 43 | + const aliasMap = { |
| 44 | + rt: 'runtime' |
| 45 | + } |
| 46 | + |
| 47 | + // Resolve alias to canonical name if it exists |
| 48 | + const commandId = args[0] |
| 49 | + if (aliasMap[commandId]) { |
| 50 | + const resolvedArgs = [aliasMap[commandId], ...args.slice(1)] |
| 51 | + return super.showHelp(resolvedArgs) |
| 52 | + } |
| 53 | + |
| 54 | + // No alias resolution needed, show help as-is |
| 55 | + return super.showHelp(args) |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +module.exports = CustomHelp |
0 commit comments