Passed
Push — main ( b7799b...6c7a2f )
by Bjarn
03:09 queued 01:45
created

src/utils/tools.ts   A

Complexity

Total Complexity 1
Complexity/F 0

Size

Lines of Code 34
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 30
dl 0
loc 34
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 Magerun from '../tools/magerun'
3
import Magerun2 from '../tools/magerun2'
4
import Tool from '../tools/tool'
5
import WpCli from '../tools/wpCli'
6
7
const getToolByName = (toolName: string): Tool => {
8
    let tool: Tool
9
10
    switch (toolName) {
11
        // TODO: Improve the way we handle these checks. This is very NOT memory efficient
12
        //  as we are constantly initiating new objects.
13
        case (new WpCli).alias || (new WpCli).name:
14
            tool = new WpCli()
15
            break
16
        case (new Magerun).alias || (new Magerun).name:
17
            tool = new Magerun()
18
            break
19
        case (new Magerun2).alias || (new Magerun2).name:
20
            tool = new Magerun2()
21
            break
22
        case (new Drush).alias || (new Drush).name:
23
            tool = new Drush()
24
            break
25
        default:
26
            throw Error('Invalid tool: ' + toolName)
27
    }
28
29
    return tool
30
}
31
32
export {
33
    getToolByName
34
}