-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommands.js
More file actions
executable file
·138 lines (128 loc) · 3.27 KB
/
commands.js
File metadata and controls
executable file
·138 lines (128 loc) · 3.27 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/env node
const program = require('commander');
var inquirer = require('inquirer');
const {
login,
logout,
fetchLogs,
changeAbout,
isLoggedIn,
pushLog,
displayAbout,
handleColorSetting,
} = require('./index');
program.version('2.0.3').description('Memory Stack');
//login
program
.command('login')
.description(
'Create an account on memorystack.live/signup and use the credentials to login'
)
.action(async () => {
const verdict = await isLoggedIn();
if (!verdict)
inquirer
.prompt([
{
name: 'username',
prefix: '$',
message: 'Enter your username',
type: 'input',
},
{
name: 'password',
prefix: '$',
message: 'Enter your password',
type: 'password',
},
])
.then((input) => {
login(input.username, input.password);
})
.catch((error) => {
if (error.isTtyError) {
// Prompt couldn't be rendered in the current environment
} else {
// Something else went wrong
}
});
else console.log('User is already logged in. Please logout to continue.');
});
//logout
program
.command('logout')
.description('Logout current user')
.action(async () => {
const isLoggedInVar = await isLoggedIn();
if (isLoggedInVar) logout();
else console.log('Please login first.');
});
//fetchLogs
program
.command('logs')
.description("Fetch all the logs you've posted today")
.action(async () => {
const isLoggedInVar = await isLoggedIn();
if (isLoggedInVar) fetchLogs();
else console.log('Please login first.');
});
//pushLog
program
.command('log <text>')
.description("How are you feeling right now? What are you upto? What's up?")
.action(async (text) => {
const isLoggedInVar = await isLoggedIn();
if (isLoggedInVar) pushLog(text);
else console.log('Please login first.');
});
//changeAbout
program
.command('setbio <text>')
.description('Change your bio')
.action(async (text) => {
const isLoggedInVar = await isLoggedIn();
if (isLoggedInVar) changeAbout(text);
else console.log('Please login first.');
});
//displayAbout
program
.command('bio')
.description('Displays your current bio')
.action(async () => {
const isLoggedInVar = await isLoggedIn();
if (isLoggedInVar) displayAbout();
else console.log('Please login first.');
});
//settings
program
.command('set <option>')
.description('Change user settings')
.action(async (option) => {
const isLoggedInVar = await isLoggedIn();
if (isLoggedInVar) {
switch (option) {
case 'color':
const colorList = [
'Red',
'Orange',
'Yellow',
'Green',
'Teal',
'Blue',
'Purple',
'Pink',
];
inquirer
.prompt([
{
name: 'color',
message: 'Select the color.',
choices: colorList,
type: 'rawlist',
},
])
.then((input) => handleColorSetting(input.color));
}
} else console.log('Please login first.');
});
program.parse(process.argv);