Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
eepm
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
etersoft
eepm
Commits
4a12841e
Commit
4a12841e
authored
May 13, 2023
by
Vitaly Lipatov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add epm tool yaml
parent
28c763da
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
124 additions
and
0 deletions
+124
-0
epm-tool
bin/epm-tool
+4
-0
tools_yaml
bin/tools_yaml
+120
-0
No files found.
bin/epm-tool
View file @
4a12841e
...
...
@@ -62,6 +62,10 @@ epm_tool()
showcmd json
"
$@
"
$CMDSHELL
$SHAREDIR
/tools_json
"
$@
"
;;
"yaml"
)
# HELPCMD: parse yaml operations
showcmd yaml
"
$@
"
$CMDSHELL
$SHAREDIR
/tools_yaml
"
$@
"
;;
"which"
)
print_command_path
"
$@
"
# HELPCMD: which like command (no output to stderr, can works without which package)
;;
...
...
bin/tools_yaml
0 → 100755
View file @
4a12841e
#!/usr/bin/env bash
# GPL-3.0 license
# source: https://github.com/mrbaseman/parse_yaml.git
function
parse_yaml
{
local
prefix
=
$2
local
separator
=
${
3
:-
_
}
local
indexfix
# Detect awk flavor
if
awk
--version
2>&1 |
grep
-q
"GNU Awk"
;
then
# GNU Awk detected
indexfix
=
-1
elif
awk
-Wv
2>&1 |
grep
-q
"mawk"
;
then
# mawk detected
indexfix
=
0
fi
local
s
=
'[[:space:]]*'
sm
=
'[ \t]*'
w
=
'[a-zA-Z0-9_]*'
fs
=
${
fs
:-$(
echo
@|tr @
'\034'
)}
i
=
${
i
:-
}
cat
$1
|
\
awk
-F
$fs
"{multi=0;
if(match(
\$
0,/
$sm
\|
$sm$/
)){multi=1; sub(/
$sm
\|
$sm$/
,
\"\"
);}
if(match(
\$
0,/
$sm
>
$sm$/
)){multi=2; sub(/
$sm
>
$sm$/
,
\"\"
);}
while(multi>0){
str=
\$
0; gsub(/^
$sm
/,
\"\"
, str);
indent=index(
\$
0,str);
indentstr=substr(
\$
0, 0, indent+
$indexfix
)
\"
$i
\"
;
obuf=
\$
0;
getline;
while(index(
\$
0,indentstr)){
obuf=obuf substr(
\$
0, length(indentstr)+1);
if (multi==1){obuf=obuf
\"\\\\
n
\"
;}
if (multi==2){
if(match(
\$
0,/^
$sm$/
))
obuf=obuf
\"\\\\
n
\"
;
else obuf=obuf
\"
\"
;
}
getline;
}
sub(/
$sm$/
,
\"\"
,obuf);
print obuf;
multi=0;
if(match(
\$
0,/
$sm
\|
$sm$/
)){multi=1; sub(/
$sm
\|
$sm$/
,
\"\"
);}
if(match(
\$
0,/
$sm
>
$sm$/
)){multi=2; sub(/
$sm
>
$sm$/
,
\"\"
);}
}
print}"
|
\
sed
-e
"s|^
\(
$s
\)
?|
\1
-|"
\
-ne
"s|^
$s
#.*||;s|
$s
#[^
\"
']*
$|
|;s|^
\(
[^
\"
'#]*
\)
#.*|
\1
|;t1;t;:1;s|^
$s
\$
||;t2;p;:2;d"
|
\
sed
-ne
"s|,
$s
\]
$s
\$
|]|"
\
-e
":1;s|^
\(
$s
\)\(
$w
\)
$s
:
$s
\(
&
$w
\)\?
$s
\[
$s
\(
.*
\)
$s
,
$s
\(
.*
\)
$s
\]
|
\1\2
:
\3
[
\4
]
\n\1
$i
-
\5
|;t1"
\
-e
"s|^
\(
$s
\)\(
$w
\)
$s
:
$s
\(
&
$w
\)\?
$s
\[
$s
\(
.*
\)
$s
\]
|
\1\2
:
\3\n\1
$i
-
\4
|;"
\
-e
":2;s|^
\(
$s
\)
-
$s
\[
$s
\(
.*
\)
$s
,
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\1
$fs$fs
\2
|"
\
-e
"s|^
\(
$s
\)\(
$w
\)
$s
:
$s
[
\"
']
\?\(
.*
\)
$s
\$
|
\1
$fs
\2
$fs
\3
|"
\
-e
"s|^
\(
$s
\)
[
\"
']
\?\(
[^&][^
$fs
]
\+\)
[
\"
']
$s
\$
|
\1
$fs$fs$fs
\2
|"
\
-e
"s|^
\(
$s
\)
[
\"
']
\?\(
[^&][^
$fs
]
\+\)
$s
\$
|
\1
$fs$fs$fs
\2
|"
\
-e
"s|
$s
\$
||p"
|
\
awk
-F
$fs
"{
gsub(/
\t
/,
\"
\"
,
\$
1);
if(NF>3){if(value!=
\"\"
){value = value
\"
\"
;}value = value
\$
4;}
else {
if(match(
\$
1,/^&/)){anchor[substr(
\$
1,2)]=full_vn;getline};
indent = length(
\$
1)/length(
\"
$i
\"
);
vname[indent] =
\$
2;
value=
\$
3;
for (i in vname) {if (i > indent) {delete vname[i]; idx[i]=0}}
if(length(
\$
2)== 0){ vname[indent]= ++idx[indent] };
vn=
\"\"
; for (i=0; i<indent; i++) { vn=(vn)(vname[i])(
\"
$separator
\"
)}
vn=
\"
$prefix
\"
vn;
full_vn=vn vname[indent];
if(vn==
\"
$prefix
\"
)vn=
\"
$prefix$separator
\"
;
if(vn==
\"
_
\"
)vn=
\"
__
\"
;
}
assignment[full_vn]=value;
if(!match(assignment[vn], full_vn))assignment[vn]=assignment[vn]
\"
\"
full_vn;
if(match(value,/^
\*
/)){
ref=anchor[substr(value,2)];
if(length(ref)==0){
printf(
\"
%s=
\\\"
%s
\\\"\n\"
, full_vn, value);
} else {
for(val in assignment){
if((length(ref)>0)&&index(val, ref)==1){
tmpval=assignment[val];
sub(ref,full_vn,val);
if(match(val,
\"
$separator
\$\"
)){
gsub(ref,full_vn,tmpval);
} else if (length(tmpval) > 0) {
printf(
\"
%s=
\\\"
%s
\\\"\n\"
, val, tmpval);
}
assignment[val]=tmpval;
}
}
}
} else if (length(value) > 0) {
printf(
\"
%s=
\\\"
%s
\\\"\n\"
, full_vn, value);
}
}END{
for(val in assignment){
if(match(val,
\"
$separator
\$\"
))
printf(
\"
%s=
\\\"
%s
\\\"\n\"
, val, assignment[val]);
}
}"
}
parse_yaml
"
$@
"
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment