bunny-cli/bin/demo.js

98 lines
2.2 KiB
JavaScript
Raw Normal View History

2023-12-22 12:59:57 +08:00
#!/usr/bin/env node
const { program } = require('commander'); // 命令行提示工具
const chalk = require('chalk'); // 终端输出颜色变化
const inquirer = require('inquirer'); // 交互选项
const ora = require('ora'); // loading效果
const spinner = ora('Loading unicorns').start(); // 注意要使用x几版本因为不支持
const figlet = require('figlet'); // 生成艺术字
2023-12-22 12:59:57 +08:00
figlet('Hello World!!', function (err, data) {
if (err) {
console.log('Something went wrong...');
console.dir(err);
return;
}
console.log(data);
2023-12-22 12:59:57 +08:00
});
figlet.text(
'Boo!',
{
font: 'Ghost',
horizontalLayout: 'default',
verticalLayout: 'default',
width: 80,
whitespaceBreak: true,
},
function (err, data) {
if (err) {
console.log('Something went wrong...');
console.dir(err);
return;
}
console.log(data);
},
2023-12-22 12:59:57 +08:00
);
console.log(
figlet.textSync('Boo!', {
font: 'Ghost',
horizontalLayout: 'default',
verticalLayout: 'default',
width: 80,
whitespaceBreak: true,
}),
2023-12-22 12:59:57 +08:00
);
setTimeout(() => {
spinner.color = 'red';
spinner.text = '网络较慢,请稍后...';
2023-12-22 12:59:57 +08:00
}, 1000);
setTimeout(() => {
spinner.succeed('下载成功!!!');
2023-12-22 12:59:57 +08:00
}, 2000);
setTimeout(() => {
spinner.fail('下载失败!!!');
2023-12-22 12:59:57 +08:00
}, 3000);
inquirer
.prompt([
/* Pass your questions in here */
{ type: 'input', name: 'food', message: '你吃什么', default: '包子' },
{ type: 'input', name: 'food', message: '吃辣吗?', default: '微辣' },
])
.then(answers => {
// Use user feedback for... whatever!!
console.log(answers);
})
.catch(error => {
if (error.isTtyError) {
// Prompt couldn't be rendered in the current environment
} else {
// Something else went wrong
}
});
2023-12-22 12:59:57 +08:00
console.log(chalk.red('文字颜色'));
2023-12-22 12:59:57 +08:00
program.name('bunny-cli').usage('<command> [options]');
2023-12-22 12:59:57 +08:00
program
.option('-d, --debug', 'output extra debugging')
.option('-s, --small', 'small pizza size')
.option('-p, --pizza-type <type>', 'flavour of pizza');
2023-12-22 12:59:57 +08:00
program
.command('clone <source> [destination]')
.description('clone a repository into a newly created directory')
.action((source, destination) => {
console.log(source, destination);
});
2023-12-22 12:59:57 +08:00
program.parse(process.argv);
const options = program.opts();
console.log(options);