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
|
* create a new standard OpenFOAM source or template file
|
||||||
|
|
||||||
type: (source|template)
|
type:
|
||||||
|
-s | -source | source
|
||||||
|
-t | -template | template
|
||||||
|
|
||||||
USAGE
|
USAGE
|
||||||
exit 1
|
exit 1
|
||||||
@ -47,16 +49,16 @@ USAGE
|
|||||||
[ "$#" -gt 1 ] || usage
|
[ "$#" -gt 1 ] || usage
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
source)
|
(-s | -source | source)
|
||||||
shift
|
shift
|
||||||
$WM_PROJECT_DIR/etc/codeTemplates/source/foamNewSource $*
|
$WM_PROJECT_DIR/etc/codeTemplates/source/foamNewSource $*
|
||||||
;;
|
;;
|
||||||
template)
|
(-t | -template | template)
|
||||||
shift
|
shift
|
||||||
$WM_PROJECT_DIR/etc/codeTemplates/template/foamNewTemplate $*
|
$WM_PROJECT_DIR/etc/codeTemplates/template/foamNewTemplate $*
|
||||||
;;
|
;;
|
||||||
*)
|
(*)
|
||||||
usage "unknown type"
|
usage "unknown type '$1'"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
|||||||
@ -35,66 +35,81 @@ Template="$WM_PROJECT_DIR/etc/codeTemplates/source/_Template"
|
|||||||
usage() {
|
usage() {
|
||||||
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
|
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
|
||||||
cat<<USAGE
|
cat<<USAGE
|
||||||
Usage: $Script <type> <ClassName>
|
Usage: $Script [OPTION] <type> <ClassName>
|
||||||
|
options:
|
||||||
|
-help print the usage
|
||||||
|
|
||||||
* create a new standard OpenFOAM source file
|
* create a new standard OpenFOAM source file
|
||||||
|
|
||||||
type: (C|H|I|IO|App)
|
type: (C|H|I|IO|App)
|
||||||
|
|
||||||
|
A ClassName starting with '-' will simply display the template
|
||||||
|
|
||||||
USAGE
|
USAGE
|
||||||
exit 1
|
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
|
# this implicitly covers a lone -help
|
||||||
[ "$#" -gt 1 ] || usage
|
[ "$#" -gt 1 ] || usage
|
||||||
|
|
||||||
className="$2"
|
|
||||||
unset subType Type
|
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-h | -help)
|
(-h | -help)
|
||||||
usage
|
usage
|
||||||
;;
|
;;
|
||||||
C|H)
|
(C|H)
|
||||||
Type=".$1"
|
Type=".$1"
|
||||||
;;
|
;;
|
||||||
I)
|
(I)
|
||||||
Type="$1.H"
|
Type="$1.H"
|
||||||
;;
|
;;
|
||||||
IO)
|
(IO)
|
||||||
Type="$1.C"
|
Type="$1.C"
|
||||||
;;
|
;;
|
||||||
app|App)
|
(app|App)
|
||||||
subType=App
|
subType=App
|
||||||
Type=".C"
|
Type=".C"
|
||||||
;;
|
;;
|
||||||
*)
|
(*)
|
||||||
usage "unknown type"
|
usage "unknown type '$1'"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
[ "$#" -eq 2 ] || usage "wrong number of arguments"
|
[ "$#" -eq 2 ] || usage "wrong number of arguments"
|
||||||
shift 2
|
shift 2
|
||||||
|
|
||||||
|
|
||||||
fileName="$className$Type"
|
if [ "${printOpt:-false}" = true ]
|
||||||
|
|
||||||
|
|
||||||
echo "$Script: Creating new interface file $fileName"
|
|
||||||
if [ -e "$fileName" ]
|
|
||||||
then
|
then
|
||||||
|
cat $Template$subType$Type
|
||||||
|
else
|
||||||
|
|
||||||
|
fileName="$className$Type"
|
||||||
|
|
||||||
|
echo "$Script: Creating new interface file $fileName"
|
||||||
|
if [ -e "$fileName" ]
|
||||||
|
then
|
||||||
echo " Error: file exists"
|
echo " Error: file exists"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# process class name
|
||||||
|
sed "s/CLASSNAME/$className/g" $Template$subType$Type > $fileName
|
||||||
|
|
||||||
# process class name
|
if [ "$subType" = App -a ! -d Make ]
|
||||||
sed "s/CLASSNAME/$className/g" $Template$subType$Type > $fileName
|
then
|
||||||
|
|
||||||
|
|
||||||
if [ "$subType" = App -a ! -d Make ]
|
|
||||||
then
|
|
||||||
wmakeFilesAndOptions
|
wmakeFilesAndOptions
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
|||||||
@ -36,12 +36,16 @@ usage() {
|
|||||||
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
|
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
|
||||||
cat<<USAGE
|
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
|
* create a new standard OpenFOAM source file for templated classes
|
||||||
|
|
||||||
type: (C|H|I|IO)
|
type: (C|H|I|IO)
|
||||||
|
|
||||||
|
A ClassName starting with '-' will simply display the template
|
||||||
|
|
||||||
USAGE
|
USAGE
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
@ -51,59 +55,76 @@ USAGE
|
|||||||
|
|
||||||
|
|
||||||
className="$2"
|
className="$2"
|
||||||
unset Type
|
unset Type printOpt
|
||||||
|
|
||||||
case "$1" in
|
# for a className starting with '-' simply display the code
|
||||||
-h | -help)
|
if [ "${2#-}" != "${2}" ]
|
||||||
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" ]
|
|
||||||
then
|
then
|
||||||
echo " Error: file exists"
|
printOpt=true
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# process class name
|
case "$1" in
|
||||||
sed -e "s/CLASSNAME/$className/g" $Template$Type > $fileName.1
|
(-h | -help)
|
||||||
|
usage
|
||||||
|
;;
|
||||||
|
(C|H)
|
||||||
|
Type=".$1"
|
||||||
|
;;
|
||||||
|
(I)
|
||||||
|
Type="$1.H"
|
||||||
|
;;
|
||||||
|
(IO)
|
||||||
|
Type="$1.C"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
usage "unknown type '$1'"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
|
||||||
# process template arguments
|
if [ "${printOpt:-false}" = true ]
|
||||||
for tArg
|
then
|
||||||
do
|
[ "$#" -eq 2 ] || usage "wrong number of arguments"
|
||||||
|
shift 2
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
# process class name
|
||||||
|
sed -e "s/CLASSNAME/$className/g" $Template$Type > $fileName.1
|
||||||
|
|
||||||
|
|
||||||
|
# process remaining (template) arguments
|
||||||
|
for tArg
|
||||||
|
do
|
||||||
sed -e "s/TemplateClassArgument/class $tArg, TemplateClassArgument/g" \
|
sed -e "s/TemplateClassArgument/class $tArg, TemplateClassArgument/g" \
|
||||||
-e "s/TemplateArgument/$tArg, TemplateArgument/g" \
|
-e "s/TemplateArgument/$tArg, TemplateArgument/g" \
|
||||||
$fileName.1 > $fileName.2
|
$fileName.1 > $fileName.2
|
||||||
|
|
||||||
mv $fileName.2 $fileName.1
|
mv $fileName.2 $fileName.1
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
# remove remaining ", Template .."
|
# remove remaining ", Template .."
|
||||||
sed -e "s/, TemplateClassArgument//g" \
|
sed -e "s/, TemplateClassArgument//g" \
|
||||||
-e "s/, TemplateArgument//g" \
|
-e "s/, TemplateArgument//g" \
|
||||||
$fileName.1 > $fileName
|
$fileName.1 > $fileName
|
||||||
|
|
||||||
rm $fileName.1
|
rm $fileName.1
|
||||||
|
fi
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user