MCPcopy Create free account
hub / github.com/acode/cli / UserCommand

Class UserCommand

cli/commands/user.js:38–213  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36};
37
38class UserCommand extends Command {
39
40 constructor() {
41
42 super('user');
43
44 }
45
46 help() {
47
48 return {
49 description: 'Retrieves (and sets) current user information',
50 flags: {
51 s: '<key> <value> Sets a specified key-value pair'
52 },
53 vflags: {
54 set: '<key> <value> Sets a specified key-value pair',
55 'new-password': 'Sets a new password via a prompt',
56 'reset-password': '<email> Sends a password reset request for the specified e-mail address'
57 }
58 };
59
60 }
61
62 async run(params, callback) {
63
64 let host = 'api.autocode.com';
65 let port = 443;
66
67 let hostname = (params.flags.h && params.flags.h[0]) || '';
68 let matches = hostname.match(/^(https?:\/\/)?(.*?)(:\d+)?$/);
69
70 if (hostname && matches) {
71 host = matches[2];
72 port = parseInt((matches[3] || '').substr(1) || (hostname.indexOf('https') === 0 ? 443 : 80));
73 }
74
75 let resource = new APIResource(host, port);
76 resource.authorize(config.get('ACCESS_TOKEN'));
77
78 // If resetting password
79 if (params.vflags['reset-password']) {
80 let resetEmail = params.vflags['reset-password'][0];
81 return resource.request('v1/password_reset_requests').create({}, {email: resetEmail}, (err, response) => {
82
83 if (err) {
84 return callback(err);
85 }
86
87 console.log('Password reset e-mail sent. Check the inbox for ' + resetEmail + ' for more details.');
88 return callback(null);
89
90 });
91 }
92
93 if (params.vflags['new-password']) {
94
95 let promptResult = await inquirer.prompt(

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected