Repository navigation
Expand file tree
/
Copy pathinit.js
More file actions
89 lines (78 loc) 路 1.69 KB
/
Copy pathinit.js
File metadata and controls
89 lines (78 loc) 路 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// importing packages
const welcome = require('cli-welcome');
const { Input } = require('enquirer');
const meow = require('meow');
const meowHelp = require('cli-meow-help');
const updateNotifier = require('update-notifier');
const pkgJSON = require('../package.json');
/*
*
* get user question
*/
const getInput = async () => {
const prompt = new Input({
name: 'question',
message: 'What is your question?'
});
let answer;
try {
answer = await prompt.run();
} catch (error) {
console.error(error);
}
return answer;
};
/**
*
* generates cli help text
*/
const cliHelpText = () => {
const commands = {
none: { desc: `No commands available for ${pkgJSON.name}` }
};
const flags = {
asc: {
desc: `Order the results in ascending order`,
default: 'desc'
},
activity: {
desc: `Sort the results according to activity date`,
default: 'relevance'
},
votes: {
desc: `Sort the results according to the number of votes`,
default: 'relevance'
},
creation: {
desc: `Sort the results according to the creation date`,
default: 'relevance'
}
};
const helpText = meowHelp({
name: `stack`,
commands,
flags
});
meow(helpText, { flags });
};
module.exports = async () => {
cliHelpText() ||
welcome({
title: `stackoverflow-cli`,
tagLine: `by ${pkgJSON.author.name}`,
description: `${pkgJSON.description}`,
bgColor: `#f48024`,
color: `#FFFFFF`,
bold: true,
clear: true,
version: `${pkgJSON.version}`
});
// Make sure user enters a question that's not an empty string
let question = '';
while (question === '') {
question = await getInput();
}
// checks for CLI update
updateNotifier({ pkg: pkgJSON }).notify();
return question;
};