mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: add '-s|-t' options for foamNew, cat to stdout on '-' prefixed class name
- eg, "foamNewSource IO -", "foamNew -s IO -" displays on stdout convenient for grabbing boilerplate directly
This commit is contained in:
12
bin/foamNew
12
bin/foamNew
@ -36,7 +36,9 @@ Usage: ${0##*/} <type> {args}
|
||||
|
||||
* create a new standard OpenFOAM source or template file
|
||||
|
||||
type: (source|template)
|
||||
type:
|
||||
-s | -source | source
|
||||
-t | -template | template
|
||||
|
||||
USAGE
|
||||
exit 1
|
||||
@ -47,16 +49,16 @@ USAGE
|
||||
[ "$#" -gt 1 ] || usage
|
||||
|
||||
case "$1" in
|
||||
source)
|
||||
(-s | -source | source)
|
||||
shift
|
||||
$WM_PROJECT_DIR/etc/codeTemplates/source/foamNewSource $*
|
||||
;;
|
||||
template)
|
||||
(-t | -template | template)
|
||||
shift
|
||||
$WM_PROJECT_DIR/etc/codeTemplates/template/foamNewTemplate $*
|
||||
;;
|
||||
*)
|
||||
usage "unknown type"
|
||||
(*)
|
||||
usage "unknown type '$1'"
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
@ -35,66 +35,81 @@ Template="$WM_PROJECT_DIR/etc/codeTemplates/source/_Template"
|
||||
usage() {
|
||||
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
|
||||
cat<<USAGE
|
||||
Usage: $Script <type> <ClassName>
|
||||
Usage: $Script [OPTION] <type> <ClassName>
|
||||
options:
|
||||
-help print the usage
|
||||
|
||||
* create a new standard OpenFOAM source file
|
||||
|
||||
type: (C|H|I|IO|App)
|
||||
|
||||
A ClassName starting with '-' will simply display the template
|
||||
|
||||
USAGE
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
||||
className="$2"
|
||||
unset subType Type printOpt
|
||||
|
||||
# for a className starting with '-' simply display the code
|
||||
if [ "${2#-}" != "${2}" ]
|
||||
then
|
||||
printOpt=true
|
||||
fi
|
||||
|
||||
|
||||
# this implicitly covers a lone -help
|
||||
[ "$#" -gt 1 ] || usage
|
||||
|
||||
className="$2"
|
||||
unset subType Type
|
||||
|
||||
case "$1" in
|
||||
-h | -help)
|
||||
(-h | -help)
|
||||
usage
|
||||
;;
|
||||
C|H)
|
||||
(C|H)
|
||||
Type=".$1"
|
||||
;;
|
||||
I)
|
||||
(I)
|
||||
Type="$1.H"
|
||||
;;
|
||||
IO)
|
||||
(IO)
|
||||
Type="$1.C"
|
||||
;;
|
||||
app|App)
|
||||
(app|App)
|
||||
subType=App
|
||||
Type=".C"
|
||||
;;
|
||||
*)
|
||||
usage "unknown type"
|
||||
(*)
|
||||
usage "unknown type '$1'"
|
||||
;;
|
||||
esac
|
||||
|
||||
[ "$#" -eq 2 ] || usage "wrong number of arguments"
|
||||
shift 2
|
||||
|
||||
|
||||
fileName="$className$Type"
|
||||
|
||||
|
||||
echo "$Script: Creating new interface file $fileName"
|
||||
if [ -e "$fileName" ]
|
||||
if [ "${printOpt:-false}" = true ]
|
||||
then
|
||||
echo " Error: file exists"
|
||||
exit 1
|
||||
fi
|
||||
cat $Template$subType$Type
|
||||
else
|
||||
|
||||
fileName="$className$Type"
|
||||
|
||||
# process class name
|
||||
sed "s/CLASSNAME/$className/g" $Template$subType$Type > $fileName
|
||||
echo "$Script: Creating new interface file $fileName"
|
||||
if [ -e "$fileName" ]
|
||||
then
|
||||
echo " Error: file exists"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# process class name
|
||||
sed "s/CLASSNAME/$className/g" $Template$subType$Type > $fileName
|
||||
|
||||
if [ "$subType" = App -a ! -d Make ]
|
||||
then
|
||||
wmakeFilesAndOptions
|
||||
if [ "$subType" = App -a ! -d Make ]
|
||||
then
|
||||
wmakeFilesAndOptions
|
||||
fi
|
||||
fi
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
@ -36,12 +36,16 @@ usage() {
|
||||
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
|
||||
cat<<USAGE
|
||||
|
||||
Usage: $Script <type> <ClassName> <Template arguments...>
|
||||
Usage: $Script [OPTION] <type> <ClassName> <Template arguments...>
|
||||
options:
|
||||
-help print the usage
|
||||
|
||||
* create a new standard OpenFOAM source file for templated classes
|
||||
|
||||
type: (C|H|I|IO)
|
||||
|
||||
A ClassName starting with '-' will simply display the template
|
||||
|
||||
USAGE
|
||||
exit 1
|
||||
}
|
||||
@ -51,59 +55,76 @@ USAGE
|
||||
|
||||
|
||||
className="$2"
|
||||
unset Type
|
||||
unset Type printOpt
|
||||
|
||||
case "$1" in
|
||||
-h | -help)
|
||||
usage
|
||||
;;
|
||||
C|H)
|
||||
Type=".$1"
|
||||
;;
|
||||
I)
|
||||
Type="$1.H"
|
||||
;;
|
||||
IO)
|
||||
Type="$1.C"
|
||||
;;
|
||||
*)
|
||||
usage "unknown type"
|
||||
;;
|
||||
esac
|
||||
[ "$#" -ge 3 ] || usage "wrong number of arguments"
|
||||
shift 2
|
||||
|
||||
fileName="$className$Type"
|
||||
|
||||
|
||||
echo "$Script: Creating new template interface file $fileName"
|
||||
if [ -e "$fileName" ]
|
||||
# for a className starting with '-' simply display the code
|
||||
if [ "${2#-}" != "${2}" ]
|
||||
then
|
||||
echo " Error: file exists"
|
||||
exit 1
|
||||
printOpt=true
|
||||
fi
|
||||
|
||||
|
||||
# process class name
|
||||
sed -e "s/CLASSNAME/$className/g" $Template$Type > $fileName.1
|
||||
case "$1" in
|
||||
(-h | -help)
|
||||
usage
|
||||
;;
|
||||
(C|H)
|
||||
Type=".$1"
|
||||
;;
|
||||
(I)
|
||||
Type="$1.H"
|
||||
;;
|
||||
(IO)
|
||||
Type="$1.C"
|
||||
;;
|
||||
*)
|
||||
usage "unknown type '$1'"
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
# process template arguments
|
||||
for tArg
|
||||
do
|
||||
sed -e "s/TemplateClassArgument/class $tArg, TemplateClassArgument/g" \
|
||||
-e "s/TemplateArgument/$tArg, TemplateArgument/g" \
|
||||
$fileName.1 > $fileName.2
|
||||
if [ "${printOpt:-false}" = true ]
|
||||
then
|
||||
[ "$#" -eq 2 ] || usage "wrong number of arguments"
|
||||
shift 2
|
||||
|
||||
mv $fileName.2 $fileName.1
|
||||
done
|
||||
cat $Template$Type
|
||||
|
||||
else
|
||||
|
||||
[ "$#" -ge 3 ] || usage "wrong number of arguments"
|
||||
shift 2
|
||||
|
||||
fileName="$className$Type"
|
||||
|
||||
echo "$Script: Creating new template interface file $fileName"
|
||||
if [ -e "$fileName" ]
|
||||
then
|
||||
echo " Error: file exists"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
# remove remaining ", Template .."
|
||||
sed -e "s/, TemplateClassArgument//g" \
|
||||
-e "s/, TemplateArgument//g" \
|
||||
$fileName.1 > $fileName
|
||||
# process class name
|
||||
sed -e "s/CLASSNAME/$className/g" $Template$Type > $fileName.1
|
||||
|
||||
rm $fileName.1
|
||||
|
||||
# process remaining (template) arguments
|
||||
for tArg
|
||||
do
|
||||
sed -e "s/TemplateClassArgument/class $tArg, TemplateClassArgument/g" \
|
||||
-e "s/TemplateArgument/$tArg, TemplateArgument/g" \
|
||||
$fileName.1 > $fileName.2
|
||||
|
||||
mv $fileName.2 $fileName.1
|
||||
done
|
||||
|
||||
|
||||
# remove remaining ", Template .."
|
||||
sed -e "s/, TemplateClassArgument//g" \
|
||||
-e "s/, TemplateArgument//g" \
|
||||
$fileName.1 > $fileName
|
||||
|
||||
rm $fileName.1
|
||||
fi
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user