I'm building a CLI using Oclif v4 with TypeScript and tsup for bundling. I want my main command to run by default, without requiring the user to type it as a subcommand.
Currently, my oclif configuration in package.json looks like this:
"oclif": {
"bin": "my-cli",
"commands": {
"strategy": "explicit",
"target": "./dist/index.js",
"identifier": "COMMANDS"
},
"dirname": "my-cli",
"topicSeparator": " "
}
And in src/index.ts:
import { Command, Flags } from "@oclif/core";
class MyCommand extends Command {
static override id = ".";
static override description = "Main command description";
static override flags = {
help: Flags.help({ char: "h" })
};
async run() {
this.log("Running main command");
}
}
export const COMMANDS = { MyCommand };
With this setup, the CLI works when I run:
my-cli MyCommand --help
But I want the command to run by default when executing:
my-cli --help
I tried changing the identifier in the oclif config to "default" and also exporting the command as default:
export default MyCommand;
But then my-cli --help only shows:
USAGE $ my-cli [COMMAND]
and running my-cli MyCommand --help fails with:
Error: Command MyCommand not found
How can I configure Oclif so that my main command is the default command, while still using the explicit command strategy?