Passed
Push — master ( ae58d1...b549a3 )
by Barry
01:11
created

runOptions.js ➔ runOption   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
nc 2
nop 3
dl 0
loc 23
rs 9.0856

1 Function

Rating   Name   Duplication   Size   Complexity  
A runOptions.js ➔ ... ➔ ??? 0 1 1
1
const {textFrom, textTo} = require('./textSnip.js')
2
const {json, jsonPrettify, jsonEllipsify, jsonSnippet, jsonDelKeys} = require('./jsonSnip.js')
3
4
export function runOption (option, args, inpObj) {
5
  // option is a string eg. '-jsonEllipsify'
6
  // arguments is an array of arguments for the option
7
  // inpObj is an object containing the text, type and json object we need to modify
8
  // this function acts as a marsheller to identify options and process them accordingly
9
  let funcs = {
10
    '--json': () => { json(inpObj) },
11
    '--prettify': () => { jsonPrettify(inpObj, args) },
12
    '--ellipsify': () => { jsonEllipsify(inpObj, args) },
13
    '--snip': () => { jsonSnippet(inpObj, args) },
14
    '--delKeys': () => { jsonDelKeys(inpObj, args) },
15
    '--from': () => { textFrom(inpObj, args, false) },
16
    '--start': () => { textFrom(inpObj, args, true) },
17
    '--to': () => { textTo(inpObj, args, false) },
18
    '--finish': () => { textTo(inpObj, args, true) }
19
  }
20
21
  if (funcs[option]) {
22
    funcs[option]()
23
  } else {
24
    inpObj.error.push("invalid option '" + option + "' for fsnip")
25
  }
26
}
27