22
33'use strict' ;
44
5- import { exec } from 'child_process' ;
6- import program from 'commander' ;
7- import notp from 'notp' ;
8- import ncp from 'copy-paste' ;
9- import base32 from 'thirty-two' ;
5+ const exec = require ( 'child_process' ) . exec ;
6+ const program = require ( 'commander' ) ;
7+ const chalk = require ( 'chalk' ) ;
8+ const notp = require ( 'notp' ) ;
9+ const ncp = require ( 'copy-paste' ) ;
10+ const base32 = require ( 'thirty-two' ) ;
11+ const updateNotifier = require ( 'update-notifier' ) ;
12+ const pkg = require ( '../package.json' ) ;
1013
14+ updateNotifier ( { pkg} ) . notify ( ) ;
1115
12- const getCode = ( service ) => {
16+ const getCode = service => {
1317 let key ;
1418 const pass = exec ( `pass 2fa/${ service } /code` ) ;
1519
16- pass . stdout . on ( 'data' , ( data ) => {
20+ pass . stdout . on ( 'data' , data => {
1721 key = data ;
1822 } ) ;
19- pass . stderr . on ( 'data' , ( data ) => {
20- console . log ( `Error: ${ data } ` ) ;
23+ pass . stderr . on ( 'data' , ( ) => {
24+ console . log ( chalk . red ( `Error: ${ service } not stored` ) ) ;
25+ process . exit ( 1 ) ;
2126 } ) ;
2227 pass . on ( 'close' , ( ) => {
2328 const totp = notp . totp . gen ( base32 . decode ( key ) ) ;
24- console . log ( totp ) ;
29+ console . log ( chalk . green ( totp ) ) ;
2530 ncp . copy ( totp . toString ( ) ) ;
2631 process . exit ( 0 ) ;
2732 } ) ;
@@ -32,7 +37,7 @@ program
3237 . parse ( process . argv ) ;
3338
3439if ( program . args . length === 0 ) {
35- console . error ( 'service required') ;
40+ console . log ( chalk . red ( 'Service required') ) ;
3641 process . exit ( 1 ) ;
3742} else {
3843 getCode ( program . args [ 0 ] ) ;
0 commit comments