Skip to content

Commit 7e414ea

Browse files
committed
[REFACTOR]: errors moved inside the getFunction, and function made class methods not static to use 'this'
Signed-off-by: ashish <[email protected]>
1 parent efac038 commit 7e414ea

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

src/commands/hash.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,19 @@ export default class Hash extends Command {
2323
const {args, flags} = this.parse(Hash)
2424

2525
// only 2 parameters required HASH_TYPE and INPUT_STRING
26-
flags.type = Hash.getHashType(flags) //by default let it be sha1
27-
args.string = Hash.getInputString(flags,args) // from either -s,-f or args
26+
flags.type = this.getHashType(flags) //by default let it be sha1
27+
args.string = this.getInputString(flags,args) // from either -s,-f or args
2828

2929
this.calculateHash(flags, args)
3030
}
3131

3232
private calculateHash(flags: any, args:any) {
33-
const hashObject = Hash.getHashObject(flags)
34-
35-
if (hashObject) {
36-
let hashed: string = hashObject.hex(args.string)
37-
Logger.success(this, `[${flags.type.toUpperCase()}] ${hashed}`)
38-
} else {
39-
Logger.error(this, 'Invalid Or Unsupported hash type')
40-
}
33+
const hashObject = this.getHashObject(flags)
34+
let hashed: string = hashObject.hex(args.string)
35+
Logger.success(this, `[${flags.type.toUpperCase()}] ${hashed}`)
4136
}
4237

43-
private static getHashObject(flags: any){
38+
private getHashObject(flags: any){
4439
switch (flags.type.toUpperCase()) {
4540
case 'SHA1':
4641
return new Hashes.SHA1()
@@ -53,15 +48,16 @@ export default class Hash extends Command {
5348
case 'RMD160':
5449
return new Hashes.RMD160()
5550
default:
56-
return undefined
51+
Logger.error(this, 'Invalid Or Unsupported hash type')
52+
return undefined // code never reach here
5753
}
5854
}
5955

60-
private static getHashType(flags: any) {
56+
private getHashType(flags: any) {
6157
return flags.type || 'sha1'
6258
}
6359

64-
static getInputString(flags: any, args:any) {
60+
public getInputString(flags: any, args:any) {
6561
// if -s or -f is not passed we will take it from args
6662
let str=''
6763
if (flags.string) //if -s given

0 commit comments

Comments
 (0)