Skip to content

Commit efcc45b

Browse files
committed
[LOG]: this added in logger to control state
1 parent 62b5ef3 commit efcc45b

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

src/commands/crypto.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,17 @@ export default class Crypto extends Command {
3636
str = args.string
3737

3838
if (!key) {
39-
Logger.error('Key is not passed')
39+
Logger.error(this,'Key is not passed')
4040
}
4141

4242
if (encryption) {
4343
if (decryption) // if both given
44-
Logger.error('Both encryption and decryption methods passed')
44+
Logger.error(this,'Both encryption and decryption methods passed')
4545
this.Encrypt(str, encryption, key)
4646
} else if (decryption) {
4747
this.Decrypt(str, decryption, key)
4848
} else {
49-
Logger.error('Neither encryption or decryption methods passed')
49+
Logger.error(this,'Neither encryption or decryption methods passed')
5050
}
5151
}
5252

@@ -60,7 +60,7 @@ export default class Crypto extends Command {
6060
let encrypted: string = crypto.encrypt(str, key).ciphertext
6161
this.log(`[${type.toUpperCase()}]: ${encrypted}`)
6262
} else {
63-
Logger.error('invalid hash type')
63+
Logger.error(this,'invalid hash type')
6464
}
6565
}
6666

@@ -72,7 +72,7 @@ export default class Crypto extends Command {
7272
let decrypted: string = crypto.decrypt(str, key)
7373
this.log(`[${type.toUpperCase()}]: ${decrypted}`)
7474
} else {
75-
Logger.error('invalid hash type')
75+
Logger.error(this,'invalid hash type')
7676
}
7777
}
7878

src/commands/hash.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default class Hash extends Command {
3030
if (flags.string) //if -s given
3131
str = flags.string
3232
else if (flags.file) {
33-
Logger.info(`reading file: ${flags.file}`)
33+
Logger.info(this, `reading file: ${flags.file}`)
3434
str = Utilities.getStringFromFile(this, flags.file)
3535
} else
3636
str = args.string
@@ -62,9 +62,9 @@ export default class Hash extends Command {
6262

6363
if (hash) {
6464
let hashed: string = hash.hex(str)
65-
Logger.success(`[${type.toUpperCase()}] ${hashed}`)
65+
Logger.success(this, `[${type.toUpperCase()}] ${hashed}`)
6666
} else {
67-
Logger.error( 'invalid hash type')
67+
Logger.error(this, 'Invalid Or Unsupported hash type')
6868
}
6969
}
7070

src/utilities/Logger.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ import * as signale from 'signale'
33
export default class Logger {
44

55
// uses signale for logging withoug thisRef
6-
public static success(message: string) {
6+
public static success(thisRef: any, message: string) {
77
signale.success(`${message}`)
88
}
9-
public static info(message: string) {
9+
public static info(thisRef: any, message: string) {
1010
signale.info(`${message}`)
1111
}
12-
public static error(message: string) {
12+
public static error(thisRef: any, message: string) {
1313
signale.error(`${message}`)
14+
thisRef.exit() //added to exit command
1415
}
1516

1617
// public static logSuccess(thisRef: any, message: string) {

src/utilities/Utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default class Utilities {
55
public static getStringFromFile(thisRef: any, filePath: string) {
66
let fileStr = ''
77
if (!fs.existsSync(filePath)) {
8-
Logger.error('reading File') // this will output error and exit command
8+
Logger.error(thisRef,`Couldn't find: ${filePath}`) // this will output error and exit command
99
} else {
1010
fileStr = fs.readFileSync(filePath, 'utf8')
1111

0 commit comments

Comments
 (0)