@@ -2,6 +2,7 @@ import type { LogLevel, RsbuildMode } from '@rsbuild/core';
22import cac , { type CAC } from 'cac' ;
33import type { ConfigLoader } from '../config' ;
44import type { Format , Syntax } from '../types/config' ;
5+ import { color } from '../utils/color' ;
56import { logger } from '../utils/logger' ;
67import { build } from './build' ;
78import { initConfig } from './initConfig' ;
@@ -42,6 +43,8 @@ export type InspectOptions = CommonOptions & {
4243 verbose ?: boolean ;
4344} ;
4445
46+ export type MfDevOptions = CommonOptions ;
47+
4548const applyCommonOptions = ( cli : CAC ) => {
4649 cli
4750 . option (
@@ -81,12 +84,12 @@ const applyCommonOptions = (cli: CAC) => {
8184export function runCli ( ) : void {
8285 const cli = cac ( 'rslib' ) ;
8386
84- cli . help ( ) ;
8587 cli . version ( RSLIB_VERSION ) ;
8688
8789 applyCommonOptions ( cli ) ;
8890
89- const buildCommand = cli . command ( 'build' , 'build the library for production' ) ;
91+ const buildDescription = `build the library for production ${ color . dim ( '(default if no command is given)' ) } ` ;
92+ const buildCommand = cli . command ( '' , buildDescription ) . alias ( 'build' ) ;
9093 const inspectCommand = cli . command (
9194 'inspect' ,
9295 'inspect the Rsbuild / Rspack configs of Rslib projects' ,
@@ -180,7 +183,7 @@ export function runCli(): void {
180183 }
181184 } ) ;
182185
183- mfDevCommand . action ( async ( options : CommonOptions ) => {
186+ mfDevCommand . action ( async ( options : MfDevOptions ) => {
184187 try {
185188 const cliMfDev = async ( ) => {
186189 const { config, watchFiles } = await initConfig ( options ) ;
@@ -201,5 +204,36 @@ export function runCli(): void {
201204 }
202205 } ) ;
203206
207+ cli . help ( ( sections ) => {
208+ // remove the default version log as we already log it in greeting
209+ sections . shift ( ) ;
210+
211+ for ( const section of sections ) {
212+ // Fix the command usage
213+ if ( section . title === 'Usage' ) {
214+ section . body = section . body . replace (
215+ '$ rslib' ,
216+ color . yellow ( '$ rslib [command] [options]' ) ,
217+ ) ;
218+ }
219+
220+ // Fix the build command name
221+ if ( section . title === 'Commands' ) {
222+ section . body = section . body . replace (
223+ ` ${ buildDescription } ` ,
224+ `build ${ buildDescription } ` ,
225+ ) ;
226+ }
227+
228+ // Simplify the help output for sub-commands
229+ if ( section . title ?. startsWith ( 'For more info' ) ) {
230+ section . title = color . dim ( ' For details on a sub-command, run' ) ;
231+ section . body = color . dim ( ' $ rslib <command> -h' ) ;
232+ } else {
233+ section . title = color . cyan ( section . title ) ;
234+ }
235+ }
236+ } ) ;
237+
204238 cli . parse ( ) ;
205239}
0 commit comments