6 Star 58 Fork 21

smart-doc-team / smart-doc-example-cn

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
yaml.sh 1.36 KB
Copy Edit Raw Blame History
上官胡闹 authored 2018-06-27 17:03 . Initial commit
#!/bin/bash
#################################################
# This function will Parse a simple YAML file
# and will output bash variables
#
# Typical Usage:
# eval $(YamlParse__parse sample.yml "PREFIX_")
#
# @param $1: The yaml file to parse
# @param $2: The prefix to append to all of the
# variables to be created
#################################################
YamlParse__parse() {
local prefix=$2
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
sed -ne "s|^\($s\):|\1|" \
-e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
awk -F$fs '{
indent = length($1)/2;
vname[indent] = $2;
for (i in vname) {if (i > indent) {delete vname[i]}}
if (length($3) > 0) {
vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
printf("%s%s%s=\"%s\"\n", "'$prefix'",vn, $2, $3);
}
}'
}
#################################################
# @param $1: The yaml file to check if there is
# a key
# @param $2: The key to check if it exists
# @echo: $Ash__TRUE if the key exists,
# $Ash__FALSE otherwise
#################################################
YamlParse__has_key() {
local line=$(grep -x "^$2:.*" "$1")
if [[ "$line" != "" ]]; then
echo "$Ash__TRUE"
else
echo "$Ash__FALSE"
fi
}
Java
1
https://gitee.com/smart-doc-team/smart-doc-example-cn.git
git@gitee.com:smart-doc-team/smart-doc-example-cn.git
smart-doc-team
smart-doc-example-cn
smart-doc-example-cn
master

Search