src/utils/tools.ts   A
last analyzed

Complexity

Total Complexity 1
Complexity/F 0

Size

Lines of Code 38
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 34
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 1
mnd 1
bc 1
fnc 0
bpm 0
cpm 0
noi 0
1
import Drush from '../tools/drush'
2
import Expose from '../tools/expose'
3
import Magerun from '../tools/magerun'
4
import Magerun2 from '../tools/magerun2'
5
import Tool from '../tools/tool'
6
import WpCli from '../tools/wpCli'
7
8
const getToolByName = (toolName: string): Tool => {
9
    let tool: Tool
10
11
    switch (toolName) {
12
    // TODO: Improve the way we handle these checks. This is very NOT memory efficient
13
    //  as we are constantly initiating new objects.
14
    case (new WpCli).alias || (new WpCli).name:
15
        tool = new WpCli()
16
        break
17
    case (new Magerun).alias || (new Magerun).name:
18
        tool = new Magerun()
19
        break
20
    case (new Magerun2).alias || (new Magerun2).name:
21
        tool = new Magerun2()
22
        break
23
    case (new Drush).alias || (new Drush).name:
24
        tool = new Drush()
25
        break
26
    case (new Expose).alias || (new Expose).name:
27
        tool = new Expose()
28
        break
29
    default:
30
        throw Error('Invalid tool: ' + toolName)
31
    }
32
33
    return tool
34
}
35
36
export {
37
    getToolByName
38
}