From d9fec85fd69d1d9ab12c71c6e64a30cdde3d57e4 Mon Sep 17 00:00:00 2001 From: Xu Song Date: Mon, 7 Jun 2021 18:03:57 +0800 Subject: [PATCH] support default title from path --- lib/plugins/console/new.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/plugins/console/new.js b/lib/plugins/console/new.js index 75df6d240b..2d841a10a6 100644 --- a/lib/plugins/console/new.js +++ b/lib/plugins/console/new.js @@ -2,6 +2,7 @@ const tildify = require('tildify'); const { magenta } = require('chalk'); +const pathLib = require('path'); const reservedKeys = { _: true, @@ -21,16 +22,24 @@ const reservedKeys = { }; function newConsole(args) { - // Display help message if user didn't input any arguments - if (!args._.length) { + + const path = args.p || args.path; + let title; + if (args._.length) { + title = args._.pop(); + } else if (path) { + // Default title + title = pathLib.basename(path); + } else { + // Display help message if user didn't input any arguments return this.call('help', {_: ['new']}); } const data = { - title: args._.pop(), + title: title, layout: args._.length ? args._[0] : this.config.default_layout, slug: args.s || args.slug, - path: args.p || args.path + path: path }; const keys = Object.keys(args);