-
Notifications
You must be signed in to change notification settings - Fork 3
/
_GetOpt.sub.cmd
86 lines (83 loc) · 2.86 KB
/
_GetOpt.sub.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
@ECHO OFF&SETLOCAL
::**********************************************************************
SET $NAME=%~n0
SET $DESCRIPTION=Parse command line options for help flags only
SET $Author=Erik Bachmann, ClicketyClick.dk (ErikBachmann@ClicketyClick.dk)
SET $SOURCE=%~f0
::----------------------------------------------------------------------
::@(#)NAME
::@(#) %$Name% -- %$Description%
::@(#)
::@(#)SYNOPSIS
::@(#) CALL %$Name% %*
::@(#)
::@(#)OPTIONS
::@(-) Flags, parameters, arguments (NOT the Monty Python way)
::@(#) -h Usage/Help page and exit 1 (Hard coded)
::@(#) --help Usage/Help page and exit 1 (Hard coded)
::@(#) -? /? Usage/Help page and exit 1 (Hard coded)
::@(#)
::@(#)DESCRIPTION
::@(#) Build named environment variables from command line options
::@(#) Slim-line version of _GetOpt
::@(#)
::@(#) Responds ONLY to help flags: -h and --help
::@(#)
::@(#) Faster than _getOpt at a ration 1:3,5
::@(#)
::@(#) NOTE!
::@(#) If you entend to nest scripts both using %$NAME% you must
::@(#) start the nested script with a SETLOCAL statement to preserve
::@(#) the callers environment!
::@(#)
::@(#)EXAMPLES:
::@(#) SET $SOURCE=%~f0
::@(#) ::Parse options to current script
::@(#) CALL %$NAME% %*&IF ERRORLEVEL 1 EXIT /B 1
::@(#)
::@(#) NOTE: "-flag" and "file" are NOT combined
::@(#)
::@(#)REQUIRES
::@(-) Dependecies
::@(#) _Debug.cmd Setting up debug environment for batch scripts
::@(#)
::@(#)EXIT STATUS
::@(-) Exit status / errorlevel is 0 if OK, otherwise 1+.
::@(#) 0 OK
::@(#) 1 Usage (or error)
::@(#)
::@(#)ENVIRONMENT
::@(-) Variables affected
::@(#) Will change environment according to the given arguments.
::@(#)
::@(#) If environment var DEBUG is defined and > 1 debug will be enabled as default.
::@(#)
::@(#)BUGS / KNOWN PROBLEMS
::@(-) If any known
::@(#)
::@(#)REQUIRES
::@(-) Dependencies
::@(#) _Debug.cmd Setting up debug environment for batch scripts
::@(#) what.cmd Show usage
::@(#)
::@(#)REFERENCES:
::@(#) https://en.wikipedia.org/wiki/Getopt
::@(#)
::@(#)SOURCE
::@(#) %$Source%
::----------------------------------------------------------------------
::History
::SET $VERSION=xx.xxx&SET $REVISION=YYYY-MM-DDThh:mm:ss&SET COMMENT=Init/Description
::SET $VERSION=00.000&SET $REVISION=2009-04-17T11:01:00&SET COMMENT=ebp/Initial
SET $VERSION=2015-11-07&SET $REVISION=17:28:00&SET $COMMENT=Clean up in debug info / ErikBachmann
::**********************************************************************
::@(#)(c)%$Version:~0,4% %$Author%
::**********************************************************************
ENDLOCAL
:MAIN
:: Check for -h and --help
ECHO:%*| findstr /I "\<[-/][-/]*h\> \<[-/][-/]*help\>" >nul 2>&1
IF NOT ERRORLEVEL 1 CALL "%~dp0\what" "%$SOURCE%" & EXIT /b 1
:: Else return quietly
EXIT /b 0
::*** End of File *****************************************************