@@ -23,24 +23,19 @@ export default class Hash extends Command {
23
23
const { args, flags} = this . parse ( Hash )
24
24
25
25
// 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
28
28
29
29
this . calculateHash ( flags , args )
30
30
}
31
31
32
32
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 } ` )
41
36
}
42
37
43
- private static getHashObject ( flags : any ) {
38
+ private getHashObject ( flags : any ) {
44
39
switch ( flags . type . toUpperCase ( ) ) {
45
40
case 'SHA1' :
46
41
return new Hashes . SHA1 ( )
@@ -53,15 +48,16 @@ export default class Hash extends Command {
53
48
case 'RMD160' :
54
49
return new Hashes . RMD160 ( )
55
50
default :
56
- return undefined
51
+ Logger . error ( this , 'Invalid Or Unsupported hash type' )
52
+ return undefined // code never reach here
57
53
}
58
54
}
59
55
60
- private static getHashType ( flags : any ) {
56
+ private getHashType ( flags : any ) {
61
57
return flags . type || 'sha1'
62
58
}
63
59
64
- static getInputString ( flags : any , args :any ) {
60
+ public getInputString ( flags : any , args :any ) {
65
61
// if -s or -f is not passed we will take it from args
66
62
let str = ''
67
63
if ( flags . string ) //if -s given
0 commit comments