-
Notifications
You must be signed in to change notification settings - Fork 3
/
0template.cmd
139 lines (126 loc) · 4.12 KB
/
0template.cmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION&::(Don't pollute the global environment with the following)
::**********************************************************************
SET $NAME=%~n0
SET $DESCRIPTION=Template for DOS batch script
SET $AUTHOR=Erik Bachmann, ClicketyClick.dk [[email protected]]
SET $SOURCE=%~f0
::@(#)NAME
::@(-) The name of the command or function, followed by a one-line description of what it does.
::@(#) %$NAME% -- %$DESCRIPTION%
::@(#)
::@(#)SYNOPSIS
::@(-) In the case of a command, a formal description of how to run it and what command line options it takes.
::@(-) For program functions, a list of the parameters the function takes and which header file contains its definition.
::@(-)
::@(#) %$NAME% [VAR]
::@(#)
::@(#)OPTIONS
::@(-) Flags, parameters, arguments (NOT the Monty Python way)
::@(#) -h Help page
::@(#)
::@ (#)
::@(#)DESCRIPTION
::@(-) A textual description of the functioning of the command or function.
::@(#)
::@(#)
::@(#)EXAMPLES
::@(-) Some examples of common usage.
::@(#)
::@(#)
::@(#)
::@ (#)EXIT STATUS
::@(-) Exit status / errorlevel is 0 if OK, otherwise 1+.
::@ (#)
::@ (#)ENVIRONMENT
::@(-) Variables affected
::@ (#)
::@ (#)
::@ (#)FILES,
::@(-) Files used, required, affected
::@ (#)
::@ (#)
::@ (#)BUGS / KNOWN PROBLEMS
::@(-) If any known
::@ (#)
::@ (#)
::@(#)REQUIRES
::@(-) Dependecies
::@(#) _Debug.cmd Setting up debug environment for batch scripts
::@(#) _GetOpt.cmd Parse command line options and create environment vars
::@(#) _Prescript.cmd
::@(#) _PostScript.cmd
::@(#)
::@ (#)SEE ALSO
::@(-) A list of related commands or functions.
::@ (#)
::@ (#)
::@ (#)REFERENCE
::@(-) References to inspiration, clips and other documentation
::@ (#) Author:
::@ (#) URL:
::@ (#)
::@(#)
::@(#)SOURCE
::@(-) Where to find this source
::@(#) %$Source%
::@(#)
::@ (#)AUTHOR
::@(-) Who did what
::@ (#) %$AUTHOR%
::*** HISTORY **********************************************************
::SET $VERSION=YYYY-MM-DD&SET $REVISION=hh:mm:ss&SET $COMMENT=Description/init
::SET $VERSION=2015-02-19&SET $REVISION=00:00:00&SET $COMMENT=Initial/ErikBachmann
SET $VERSION=2016-03-14&SET $REVISION=10:00:00&SET $COMMENT=Set "%~dp0\ prefix on function calls / ErikBachmann
::**********************************************************************
::@(#){COPY}%$VERSION:~0,4% %$Author%
::**********************************************************************
::ENDLOCAL
:MAIN
:: Initiating global environmen
CALL "%~dp0\_PreScript" %* || (CALL %~dp0\_PostScript & EXIT /B 1 )
:: Initiating Local environmen
CALL :Init %*
:: DO what you have to do!
:: DoSomething returns the argument as errorlevel
:: 0 = OK
CALL :CallFunc "Do something 0" ":DoSomething 0"
:: 1 = error
CALL :CallFunc "Do something 1" :DoSomething 1
:: none = OK
CALL :CallFunc "Do something none" :DoSomething
:: callfunc
CALL :CallFunc "Do something callfunc" ":DoSomething"
:: call with error
CALL :CallFunc "DIR out error" ">out.err.txt 2>&1" "DIR /w XX: "
:: successfull call
CALL :CallFunc "DIR out OK" ">>out.ok.txt 2>&1" "DIR /b %SystemDrive%\"
:: Post processing
CALL "%~dp0\_PostScript"
GOTO :EOF
::----------------------------------------------------------------------
:: Local initiation for this script only
:init
SET $Status=0
::IF /I "" equ "%~1" %_VERBOSE_% NO Arguments [%~1] - using defaults
GOTO :EOF
::---------------------------------------------------------------------
:: Dummy function
:DoSomething arg
::exit /b 0
EXIT /b %1
GOTO :EOF
::---------------------------------------------------------------------
:: SubFunction handling status reports, verbose info and trace
:CallFunc [Argument]
CALL "%~dp0\_Action" "%~1"
CALL %~2 %~3 %~4 %~5 %~6 %~7 %~8 %~9
%_DEBUG_% ErrorLevel: [%ErrorLevel%]
IF ERRORLEVEL 1 (
SET /A $ErrorLevel+=%ErrorLevel%
CALL "%~dp0\_STATUS" "Failure"
) ELSE (
CALL "%~dp0\_Status" OK
)
GOTO :EOF
::*** End of File ******************************************************