| 8 | const config = require('../config.js'); |
| 9 | |
| 10 | class LogoutCommand extends Command { |
| 11 | |
| 12 | constructor() { |
| 13 | |
| 14 | super('logout'); |
| 15 | |
| 16 | } |
| 17 | |
| 18 | help() { |
| 19 | |
| 20 | return { |
| 21 | description: 'Logs out of Autocode in this workspace', |
| 22 | flags: { |
| 23 | 'f': 'Force - clears information even if current Access Token invalid' |
| 24 | }, |
| 25 | vflags: { |
| 26 | 'force': 'Force - clears information even if current Access Token invalid' |
| 27 | } |
| 28 | }; |
| 29 | |
| 30 | } |
| 31 | |
| 32 | run(params, callback) { |
| 33 | |
| 34 | let host = params.flags.h ? params.flags.h[0] : 'https://api.autocode.com'; |
| 35 | let port = params.flags.p && params.flags.p[0]; |
| 36 | |
| 37 | let force = !!(params.flags.f || params.vflags.force); |
| 38 | |
| 39 | let resource = new APIResource(host, port); |
| 40 | resource.authorize(config.get('ACCESS_TOKEN')); |
| 41 | |
| 42 | resource.request('v1/access_tokens').destroy(null, {}, (err, response) => { |
| 43 | |
| 44 | if (!force && err) { |
| 45 | return callback(err); |
| 46 | } |
| 47 | |
| 48 | config.set('ACCESS_TOKEN', ''); |
| 49 | config.set('ACTIVE_LIBRARY_TOKEN', ''); |
| 50 | config.unset('LIBRARY_TOKENS'); |
| 51 | config.write(); |
| 52 | return callback(null, 'Logged out successfully'); |
| 53 | |
| 54 | }); |
| 55 | |
| 56 | } |
| 57 | |
| 58 | } |
| 59 | |
| 60 | module.exports = LogoutCommand; |
nothing calls this directly
no outgoing calls
no test coverage detected