You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
3.01-QCM_MuscuMaths/WebApi/convertirJson.sh

35 lines
784 B

#!/bin/bash
if test "$1" = "--help" && test "$2" = "" ; then
cat << EOF
param 1 : name of the fake datas json file to convert
param 2 : name of class this is for
(param 3 : name of the repertorie with all C# fake datas files)
EOF
exit 0
fi
if test $# -lt 2 ; then
echo "error : param require" >&2
exit 1
fi
count=$( echo $1 | tr "." "\n" | wc -l )
name=$( echo $1 | cut -d '.' -f -$(( $count - 1 )) )
if test "$3" != "" ; then
target=$( echo "$3/$name.cs" )
else
target=$( echo "$name.cs" )
fi
if test "$3" != "" ; then
if ! ls | egrep -q "^$3$" ; then
mkdir -p $3
fi
fi
cat fake-Answers.json | sed 's/:/ =/g' \
| sed "s/{/new $2{/g" | sed "s/]/} ;/g" \
| sed "s/\[/IEnumerable<$2> $name = new List<$2>\{/g" \
| sed 's/ \"/ /g' | sed 's/" =/ =/g' >$target