FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
rebash/src/utils/parseArgs.js at master · lpan/rebash · GitHub
lpan
/
rebash
Public
Notifications
You must be signed in to change notification settings
Fork
1
Star
13
Code
Issues
2
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
rebash
/
src
/
utils
/
parseArgs.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
44 lines (33 loc) · 1.2 KB
Breadcrumbs
rebash
/
src
/
utils
/
parseArgs.js
Copy path
File metadata and controls
44 lines (33 loc) · 1.2 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import
{
split
,
take
,
T
,
equals
,
tail
,
compose
,
reduce
,
cond
,
objOf
,
head
,
mergeWith
,
drop
,
concat
,
flip
,
append
,
map
,
}
from
'ramda'
;
// need to make it an array so we can use concat
// We use concat because user can inputs multiple flags at once
// eg. 'ls -al' -> ['a', 'l']
const
toArray
=
flip
(
append
)
(
[
]
)
;
const
parseFlag
=
compose
(
objOf
(
'flags'
)
,
split
(
''
)
,
tail
)
;
const
parseOption
=
compose
(
objOf
(
'fulls'
)
,
toArray
,
drop
(
2
)
)
;
const
parseTarget
=
compose
(
objOf
(
'targets'
)
,
toArray
)
;
const
classifyArg
=
cond
(
[
[
compose
(
equals
(
'--'
)
,
take
(
2
)
)
,
parseOption
]
,
[
compose
(
equals
(
'-'
)
,
head
)
,
parseFlag
]
,
[
T
,
parseTarget
]
,
]
)
;
const
mergeArg
=
mergeWith
(
concat
)
;
const
formatArgs
=
reduce
(
(
accum
,
current
)
=>
mergeArg
(
accum
,
classifyArg
(
current
)
)
,
{
fulls
:
[
]
,
flags
:
[
]
,
targets
:
[
]
}
)
;
const
getArgs
=
compose
(
tail
,
split
(
' '
)
)
;
const
sortArgs
=
map
(
args
=>
args
.
sort
(
)
)
;
/**
* Parse raw command and returns an args object
* 'ls -a -l --lmao' -> {targets: [], flags: ['a', 'l'], fulls: ['lmao']}
*
*
@param
{
String
} Command - raw command from user
*
*
@returns
{
obj
} - {fulls: [], flags: [], targets: []}
*/
const
parseArgs
=
compose
(
sortArgs
,
formatArgs
,
getArgs
)
;
export
default
parseArgs
;
Back
|
FazBrowse Home
|
New Git URL