diff --git a/README.md b/README.md index 06f28a8b..3d3cec7a 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ $ egg-bin dev - `--framework` egg web framework root path. - `--baseDir` application's root path, default to `process.cwd()`. - `--port` server port, default to `7001`. -- `--cluster` worker process number, skip this argvs will start only `1` worker, provide this without value will start `cpu` count worker. +- `--workers` worker process number, default to `1` worker at local mode. - `--sticky` start a sticky cluster server, default to `false`. - `--typescript` / `--ts` enable typescript support, default to `false`. Also support read from `package.json`'s `egg.typescript`. - `--declarations` / `--dts` enable [egg-ts-helper](https://github.com/whxaxes/egg-ts-helper) support, default to `false`. Also support read from `package.json`'s `egg.declarations`. diff --git a/lib/cmd/dev.js b/lib/cmd/dev.js index dc7a146c..4d6248ff 100644 --- a/lib/cmd/dev.js +++ b/lib/cmd/dev.js @@ -19,10 +19,11 @@ class DevCommand extends Command { description: 'directory of application, default to `process.cwd()`', type: 'string', }, - cluster: { - description: 'numbers of app workers, if not provide then only 1 worker, provide without value then `os.cpus().length`', + workers: { + description: 'numbers of app workers, default to 1 at local mode', type: 'number', - alias: 'c', + alias: [ 'c', 'cluster' ], + default: 1, }, port: { description: 'listening port, default to 7001', @@ -73,7 +74,7 @@ class DevCommand extends Command { /** * format egg startCluster args then change it to json string style - * @method helper#formatArgs + * @function helper#formatArgs * @param {Object} context - { cwd, argv } * @return {Array} pass to start-cluster, [ '{"port":7001,"framework":"egg"}' ] */ @@ -84,7 +85,6 @@ class DevCommand extends Command { /* istanbul ignore next */ if (!path.isAbsolute(argv.baseDir)) argv.baseDir = path.join(cwd, argv.baseDir); - argv.workers = argv.cluster || 1; argv.port = argv.port || argv.p; argv.framework = utils.getFrameworkPath({ framework: argv.framework, diff --git a/test/lib/cmd/dev.test.js b/test/lib/cmd/dev.test.js index d976467b..69141cc8 100644 --- a/test/lib/cmd/dev.test.js +++ b/test/lib/cmd/dev.test.js @@ -90,6 +90,17 @@ describe('test/lib/cmd/dev.test.js', () => { .end(done); }); + it('should startCluster with --workers=2', done => { + coffee.fork(eggBin, [ 'dev', '--workers=2' ], { cwd }) + // .debug() + .expect('stdout', /"workers":2/) + .expect('stdout', /"baseDir":".*?demo-app"/) + .expect('stdout', /"framework":".*?aliyun-egg"/) + .notExpect('stdout', /"cluster"/) + .expect('code', 0) + .end(done); + }); + it('should startCluster with --baseDir=root', done => { coffee.fork(eggBin, [ 'dev', `--baseDir=${cwd}` ]) // .debug()