-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsample.cmd
1515 lines (1281 loc) · 42.8 KB
/
sample.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
@echo off
@REM ---------------------------------------------------------------------
@REM sample.cmd to demonstrate macros, sourcing and functions
@REM 2023-05-13 sob01: created
@REM ---------------------------------------------------------------------
@REM
@REM Variable expansion means replace a variable enclosed in % or ! by its value.
@REM The %normal% expansion happen just once, before a line is executed. This means that a %variable% expansion have the same value no matters if the line is executed several times (like in a for command).
@REM The !delayed! expansion is performed each time that the line is executed.
@REM See this example:
@REM
@REM @echo off
@REM setlocal EnableDelayedExpansion
@REM set "var=Original"
@REM set "var=New" & echo Normal: "%var%", Delayed: "!var!"
@REM Output: Normal: "Original", Delayed: "New"
@REM
@REM Another one:
@REM
@REM @echo off
@REM setlocal EnableDelayedExpansion
@REM set "var1=Normal"
@REM set "var2=Delayed"
@REM for /L %%i in (1,1,10) do (
@REM set "var1=%var1% %%i"
@REM set "var2=!var2! %%i"
@REM )
@REM echo Normal: "%var1%"
@REM echo Delayed: "%var2%"
@REM Output:
@REM
@REM Normal: "Normal 10"
@REM Delayed: "Delayed 1 2 3 4 5 6 7 8 9 10"
@REM Normal expansion is not necessarily a disadvantage, but depends on the specific situation it is used. For example, in any other programming languages, to exchange the value of two variables you need the aid of a third one, but in Batch it can be done in just one line:
@REM
@REM set "var1=%var2%" & set "var2=%var1%"
@REM
@REM echo Full path and filename: %~f0
@REM echo Drive: %~d0
@REM echo Path: %~p0
@REM echo Drive and path: %~dp0
@REM echo Filename without extension: %~n0
@REM echo Filename with extension: %~nx0
@REM echo Extension: %~x0
@REM echo file date time : %~t0
@REM echo file size: %~z0
@REM
@REM The related rules are following.
@REM
@REM %~I - expands %I removing any surrounding quotes ("")
@REM %~fI - expands %I to a fully qualified path name
@REM %~dI - expands %I to a drive letter only
@REM %~pI - expands %I to a path only
@REM %~nI - expands %I to a file name only
@REM %~xI - expands %I to a file extension only
@REM %~sI - expanded path contains short names only
@REM %~aI - expands %I to file attributes of file
@REM %~tI - expands %I to date/time of file
@REM %~zI - expands %I to size of file
@REM %~$PATH:I - searches the directories listed in the PATH
@REM environment variable and expands %I to the
@REM fully qualified name of the first one found.
@REM If the environment variable name is not
@REM defined or the file is not found by the
@REM search, then this modifier expands to the
@REM empty string
@REM
@REM You can get the file name, but you can also get the full path,
@REM depending what you place between the '%~' and the '0'. Take your pick from
@REM d -- drive
@REM p -- path
@REM n -- file name without extension
@REM x -- extension
@REM f -- full path
@REM Argument Handling Example
@REM :: Take the host pattern
@REM SET FIRST_ARG=%1
@REM shift
@REM :: Get the last argument
@REM set ARG=""
@REM IF "%1"=="" GOTO Continue
@REM set ARG=%1
@REM shift
@REM :Loop
@REM IF "%~1"=="" GOTO Continue
@REM set ARG=%ARG% %1
@REM SHIFT
@REM GOTO Loop
@REM :Continue
@REM
@REM ---------------------------------------------------------------------
@REM Setting script variables
@echo off
setlocal enableextensions
@REM =====================================================================
@REM script variables
set _SCRIPT=%~n0
set _SCRIPTNAME=%0
@REM =====================================================================
@REM @echo Params "%*"
@REM =====================================================================
@REM check mandatory parameter
if "[%*]"=="[]" (
@echo. & @echo Usage: %_SCRIPT% ^(options^) ^[params^]
@echo Type %_SCRIPT% -h for more information.
endlocal
exit /b)
"@REM .gitignore"
_current_project
log
tmp
exp/done
"@REM oad.cmd"
@REM ---------------------------------------------------------------------
@REM odev.bat
@echo off
setlocal enableextensions
@REM =====================================================================
@REM script variables
set _SCRIPT=%~n0
set _SCRIPTNAME=%0
set _SCRIPT_BANNER="------------ SPM - Software Project Maker 2023 ------------"
@REM =====================================================================
@REM @echo Params "%*"
@REM =====================================================================
@REM check mandatory parameter
if "[%*]"=="[]" (
@echo. & @echo Usage: %_SCRIPT% ^(options^) ^[params^]
@echo Type %_SCRIPT% -h for more information.
endlocal
exit /b)
@REM =====================================================================
@REM script variables
@REM Folders
set _SCRIPTDIR=%~dp0
set _ARCDIR=%_SCRIPTDIR%arc
set _BLDDIR=%_SCRIPTDIR%bld
set _DOCDIR=%_SCRIPTDIR%doc
set _LIBDIR=%_SCRIPTDIR%lib
set _LOGDIR=%_SCRIPTDIR%log
set _SRCDIR=%_SCRIPTDIR%src
set _TMPDIR=%_SCRIPTDIR%tmp
@REM Subfolders
set _SCRIPT_SUBFOLDERS=arc,arc\builds,arc\sources,arc\documents,bld,doc,lib,log,src,tmp
@REM Files and gitignores
set _GITIGNORE=.gitignore
set _CURRENT_PROJECT_FILE=_current_project
set _LOGFILE=%_SCRIPT%.log
set _READMETXT=README.txt
set _HTDOCMD=README.md
set _HELPTXT=%_SCRIPT%_help.txt
@REM full qualified filenames
set _README=%_SCRIPTDIR%%_READMETXT%
set _HTDOC=%_DOCDIR%\%_HTDOCMD%
set _HELP_FILE=%_DOCDIR%\%_HELPTXT%
set _LOG_FILE=%_LOGDIR%\%_LOGFILE%
set _SCRIPT_GITIGNORE_OBJETCS=%_CURRENT_PROJECT_FILE%,arc,log,tmp
@REM Scripts
set _INI=%_SCRIPTDIR%%_SCRIPT%.ini
set _UTILS=%_SCRIPTDIR%%_SCRIPT%utl.cmd
set _MACROS=%_SCRIPTDIR%%_SCRIPT%mac.cmd
set _DEFAULTS=%_SCRIPTDIR%%_SCRIPT%def.cmd
set _FUNCTIONS=%_SCRIPTDIR%%_SCRIPT%fnc.cmd
@REM Settings
set "LogLevels[OFF]=0"
set "LogLevels[INFO]=1"
set "LogLevels[DEBUG]=2"
set "LogLevels[TRACE]=3"
set "LogSeverities[0]=OFF"
set "LogSeverities[1]=INFO"
set "LogSeverities[2]=DEBUG"
set "LogSeverities[3]=TRACE"
@REM Values
set "_TRUE_VALS=TRUE,true,YES,yes,Y,y,0"
set "_FALSE_VALS=FALSE,false,NO,no,N,n,1"
@REM =====================================================================
@REM script defaults
@REM =====================================================================
@REM calling macros
call %_MACROS%
@REM =====================================================================
@REM calling defaults
call %_DEFAULTS%
@REM =====================================================================
@REM Initialize
call :_log_debug %_line%
call :_log_debug "%_SCRIPT_BANNER:"=%"
call :_log_debug %_line%
call :_log_debug "Initializing %_SCRIPT%..."
call :_log_trace %_line%
call :_log_trace "Script: %_SCRIPT%"
call :_log_trace "Script Current Parameter: %*"
call :_log_trace "Script Ini File: %_INI%"
call :_log_trace "Script Log File: %_LOG_FILE%"
call :_log_trace "Script Help File: %_HELP_FILE%"
call :_log_trace "Script Util File: %_UTILS%"
call :_log_trace "Script Macros File: %_MACROS%"
call :_log_trace "Script Defaults File: %_DEFAULTS%"
call :_log_trace "Script Functions File: %_FUNCTIONS%"
@REM =====================================================================
@REM calling INI
call :_log_debug "%_SCRIPT%: Reading INI File: %_INI%"
for /f "tokens=1* delims==" %%a in ('type %_INI%^|findstr /V /R "^;.*" ') do (
call set "%%a=%%b"
)
@REM =====================================================================
@REM calling Current Project
if exist %_SCRIPTDIR%%_CURRENT_PROJECT_FILE% (
call :_log_debug "%_SCRIPT%: Setting Project from %_CURRENT_PROJECT_FILE%"
for /f "tokens=1* delims==" %%a in ('type %_SCRIPTDIR%%_CURRENT_PROJECT_FILE%') do (
call set "%%a=%%b"
)
)
if exist %_SCRIPTDIR%%_CURRENT_PROJECT_FILE% (
if not [%_PROJECT%]==[] (
call :_log_debug "%_SCRIPT%: Current Project is: %_PROJECT%"
) else (
call :_log_warning "%_SCRIPT%: No Project set."
)
)
@REM =====================================================================
@REM Setting Log Level
@REM (ini directive: _LOG_LEVEL)
call :_set-log-level %_LOG_LEVEL%
@REM =====================================================================
@REM create missing files and folders
@REM (ini directives: _CREATE_IF_NOT_EXISTS and _CREATE_GITIGNORE)
call :_make_gitignore "%_SCRIPTDIR%%_GITIGNORE%" "%_SCRIPT_GITIGNORE_OBJETCS%"
call :_create_project_folders "%_SCRIPTDIR%" "%_SCRIPT_SUBFOLDERS%"
@REM =====================================================================
@REM make Help Files and README if not exist
@REM (def directives: _CREATE_README, _CREATE_HTDOC, _CREATE_HELP)
call :_make_helpfiles "%_SCRIPT%" "%_README%" "%_HTDOC%" "%_HELP_FILE%"
@REM =====================================================================
@REM call arg parser
call :_log_debug %_line%
call :_log_debug "%_SCRIPT%: Running Parse Arguments"
call :parse_args %*
@REM =====================================================================
@REM --- process results and set runtime variables by options and params
@REM =====================================================================
@REM set encoding and codepage
SET NLS_LANG=%_ENCODING%
chcp %_CODEPAGE%>nul
call :_log_trace "%_SCRIPT%: Encoding: %NLS_LANG% - Codepage: %_CODEPAGE%"
call :_log_debug %_line%
@REM =====================================================================
@REM display help and exit
if exist "%_HELP_FILE%" (
if "%_DISPLAY_HELP%" == "Y" (
call :_help
goto:eof
)
) else (
call :_log_warning "%_SCRIPT%: No Help found."
goto:eof
)
@REM =====================================================================
@REM setting log_level again
@REM (ini directive: _LOG_LEVEL can be modified by -d and -t option)
call :_log_debug "%_SCRIPT%: Setting Log Level %_LOG_LEVEL%..."
call :_set-log-level %_LOG_LEVEL%
@REM =====================================================================
@REM set options and defaults
@REM =====================================================================
@REM trace call after parse args
call :_log_trace %_line%
call :_log_trace "%_SCRIPT%: Script Parameter: _PARAM=%_PARAM%"
@REM =====================================================================
@REM initialize log
call :_log_info %_line%
call :_log_info "%_SCRIPT_BANNER:"=%"
call :_log_info %_line%
@REM =====================================================================
@REM CONFIG
:_CONF
if not "%_PARAM%"=="CONFIG" goto:_MAKE
@REM valid config options for script
set "_CONFIG_OPTIONS=set-project,sp,set-ticket,st,sl,set-log-level,set-keep-files,sk,set-create-if-not-exist,sce"
set "_KEEP_VALS=ARCHIVE,archive,ALL,all,N,NONE,n,none,MOVE,move,COPY,copy"
@REM modify config options
set _OPT_VAL=%_OPTION_VALUE:"=%
set _OPT_VAL=%_OPT_VAL::=%
set _OPT_VAL=%_OPT_VAL:+=%
call :_log_trace "%_SCRIPT%: _OPTION_VALUE=%_OPTION_VALUE% _OPT_VAL="%_OPT_VAL%""
if "%_OPT_VAL%."=="." (
call :_log_info "%_SCRIPT%: Usage: %_SCRIPT% [-c config] [/opt1 value (/opt2 value /opt3 value...)])."
call :_log_debug "%_SCRIPT%: Config Options: %_CONFIG_OPTIONS%"
call :_log_error "%_SCRIPT%: Parameter: %_PARAM% No Option provided..."
goto:eof
) else (
@REM Option provided, so check it
call :_log_debug "%_SCRIPT%: Parameter: %_PARAM% Checking Options..."
call :_parse_config_options "%_OPTION_VALUE%" _PROJECT _TICKET _KEEP_FILES _CREATE_IF_NOT_EXISTS _LOG_LEVEL
)
if %ERRORLEVEL% GTR 0 (
call :_log_error "%_SCRIPT%: Parameter "%_PARAM%" returned with errors. Ckeck your inputs..." %ERRORLEVEL%
call :_log_error %_line%
goto:eof
)
if not [%_PROJECT%]==[] (
call :_log_info "%_SCRIPT%: Project configured: %_PROJECT%"
call :_log_debug "%_SCRIPT%: _PROJECT_ROOT=%_PROJECT_ROOT%"
call :_write_project_conf %_PROJECT%
)
@REM Directories based on _PROJECT_ROOT
set "_PROJECT_FOLDER=%_PROJECT_ROOT%\%_PROJECT_FOLDER_PREFIX%%_PROJECT%\"
set _PRJDOC=%_PROJECT_FOLDER%%_PROJECT_DOC_DIR%
@REM Project Doc Directory
call :_log_debug "%_SCRIPT%: _PRJDOC=%_PRJDOC%"
if exist %_PROJECT_FOLDER% (
call :_log_info "%_SCRIPT%: Project Folder %_PROJECT_FOLDER% exists."
call :_make_project_subfolders "%_PROJECT_FOLDER%" "%_PROJECT_SUBFOLDERS%"
call :_make_helpfiles "%_PROJECT%" "%_PROJECT_FOLDER%\%_READMETXT%" "%_PRJDOC%\%_HTDOCMD%" "%_PRJDOC%\%_HELPTXT%"
)
@REM set subfolder variables (excluding sub-subfolders)
for %%g in (%_PROJECT_SUBFOLDERS%) do (
setlocal enabledelayedexpansion
for /f "tokens=*" %%y in ('@echo %%g^|findstr /V /R "^.*\\.*$"') do (
call set "_PROJECT_%%y_DIR=%_PROJECT_FOLDER%%%y"
call :_log_trace "%_SCRIPT%: Setting _PROJECT_%%y_DIR=%%y"
)
)
endlocal
@REM Check if Ticket is set
if [%_TICKET%]==[] (
if not [%_PROJECT%]==[] (
call :_log_info "%_SCRIPT%: Ticket NOT set. Try setting it from Project name."
call :_log_debug "%_SCRIPT%: PROJECT_KEYS=%_PROJECT_KEYS:"=%"
call :_get-ticket-from-project %_PROJECT_KEYS% "%_PROJECT%"
)
)
if not [%_TICKET%]==[] (
call :_log_info "%_SCRIPT%: Ticket set: %_TICKET%"
) else (
call :_log_warning "%_SCRIPT%: Ticket not set. GIT functionality will not be available."
)
@REM Script Option Processing (only visible in DEBUG mode)
@REM Log Level
:_LOGLEV
if [%_LOG_LEVEL%]==[] goto :_KEEPFILES
call :_log_debug "%_SCRIPT%: Option LOG_LEVEL set: %_LOG_LEVEL%"
@REM check KEEP_FILES
:_KEEPFILES
if [%_KEEP_FILES%]==[] goto:_CINE
call :_check_option_value "%_KEEP_FILES%" "%_KEEP_VALS%" _NOTFOUND
if "%_NOTFOUND%" NEQ "0" (
call :_log_error "%_SCRIPT%: Invalid KEEP_FILES Value: %_KEEP_FILES%" & goto:eof
) else (
call :_log_debug "%_SCRIPT%: Option KEEP_FILES set: %_KEEP_FILES%"
)
@REM check CreateIfNotExists
:_CINE
if [%_CREATE_IF_NOT_EXISTS%]==[] goto :EOF_CONFIG
call :_check_option_value "%_CREATE_IF_NOT_EXISTS%" "%_TRUE_VALS%" _NOTFOUND
if "%_NOTFOUND%" NEQ "0" (
call :_log_error "%_SCRIPT%: Invalid CREATE_IF_NOT_EXISTS Value: %_CREATE_IF_NOT_EXISTS%" & goto:eof
) else (
call :_log_debug "%_SCRIPT%: Option CREATE_FOLDER_IF_NOT_EXISTS set: %_CREATE_IF_NOT_EXISTS%"
)
@REM EOF Config
:EOF_CONFIG
@REM =====================================================================
@REM MAKE
:_MAKE
if not "%_PARAM%"=="MAKE" goto:_RUN
@REM valid make options for script
set "_MAKE_OPTIONS=project,p,build,b,install,i,clean,c"
set _MAKE_OPT_ARG=
call :_log_trace "%_SCRIPT%: %_PARAM% _MAKE_WHAT=%_MAKE_WHAT% _MAKE_VALUE=%_MAKE_VALUE% _MAKE_OPT_ARG=%_MAKE_OPT_ARG%"
if [%_MAKE_VALUE%]==[] (
call :_log_info "%_SCRIPT%: Usage: %_SCRIPT% [-m make] [/opt1 value (/opt2 value /opt3 value...)])."
call :_log_debug "%_SCRIPT%: MAKE Options: %_MAKE_OPTIONS%"
call :_log_error "%_SCRIPT%: Parameter: %_PARAM% no Value provided for Option %_MAKE_WHAT%..."
goto:eof
) else (
@REM Option provided, so check it
call :_log_debug "%_SCRIPT%: Parameter: %_PARAM% Checking Option %_MAKE_WHAT%..."
call :_parse_make_options "%_MAKE_WHAT%" "%_MAKE_OPTIONS%"
)
if %ERRORLEVEL% GTR 0 (
call :_log_error "%_SCRIPT%: Parameter "%_PARAM%" returned with errors. Ckeck your inputs..." %ERRORLEVEL%
call :_log_error %_line%
set _MAKE_OPT_ARG=
goto:eof
)
@REM determine what to make
call :_log_info "%_SCRIPT%: MAKE Option: %_MAKE_WHAT% Value: %_MAKE_VALUE% %_MAKE_OPT_ARG%"
if "%_MAKE_WHAT%" == "project" goto:_PROJ
if "%_MAKE_WHAT%" == "p" goto:_PROJ
if "%_MAKE_WHAT%" == "build" goto:_BUILD
if "%_MAKE_WHAT%" == "b" goto:_BUILD
if "%_MAKE_WHAT%" == "install" goto:_INSTALL
if "%_MAKE_WHAT%" == "i" goto:_INSTALL
goto :_RUN
:_PROJ
call :_log_info "%_SCRIPT%: Making %_MAKE_WHAT%: %_MAKE_VALUE% %_MAKE_OPT_ARG%"
call :_log_info %_line%%
@REM =====================================================================
@REM Your great Project here
@REM =====================================================================
@REM Directories based on _MAKE_VALUE
SET "_PROJECT_FOLDER=%_PROJECT_ROOT%\%_PROJECT_FOLDER_PREFIX%%_MAKE_VALUE%\"
set _PRJDOC=%_PROJECT_FOLDER%%_PROJECT_DOC_DIR%
call :_log_debug "%_SCRIPT%: Project Documents: %_PRJDOC%"
if not exist %_PROJECT_FOLDER% (
call :_log_info "%_SCRIPT%: Making Project Folder %_PROJECT_FOLDER%..."
call :_make_folder %_PROJECT_FOLDER% && call :_log_info "%_SCRIPT%: Done..."
goto :_MAKE_SUBFOLDERS
)
@echo _MAKE_OPT_ARG=%_MAKE_OPT_ARG%
if exist %_PROJECT_FOLDER% (
if not ["%_MAKE_OPT_ARG%"]==["clean"] (
call :_log_error "%_SCRIPT%: Project Folder %_PROJECT_FOLDER% exists."
call :_log_error "%_SCRIPT%: Consider renaming your Project..." && %_ex_error%
)
)
:_MAKE_SUBFOLDERS
if exist %_PROJECT_FOLDER% (
call :_make_project_subfolders "%_PROJECT_FOLDER%" "%_PROJECT_SUBFOLDERS%"
call :_make_helpfiles "%_PROJECT%" "%_PROJECT_FOLDER%\%_READMETXT%" "%_PRJDOC%\%_HTDOCMD%" "%_PRJDOC%\%_HELPTXT%"
)
goto:_RUN
:_BUILD
call :_log_info "%_SCRIPT%: Making %_MAKE_WHAT%: %_MAKE_VALUE% %_MAKE_CLEAN%"
@REM Your great Build Script here
goto:_RUN
:_INSTALL
call :_log_info "%_SCRIPT%: Making %_MAKE_WHAT%: %_MAKE_VALUE% %_MAKE_CLEAN%"
@REM Your great Install Script here
goto :_RUN
@REM =====================================================================
@REM RUN
:_RUN
if not "%_PARAM%"=="RUN" goto:_GET
if "%_PARAM%"=="MAKE" (
call :_log_info "%_SCRIPT%: Parameter: %_PARAM% Checking Options..."
call :_log_info "%_SCRIPT%: no %_PARAM% options currently supported..."
)
@REM =====================================================================
@REM GET / SHOW Parameters and Options
:_GET
if not "%_PARAM%"=="GET" goto:_continue
if "%_PARAM%"=="GET" (
call :_log_info "%_SCRIPT%: Parameter: %_PARAM% Checking Options..."
call :_log_info "%_SCRIPT%: no %_PARAM% options currently supported..."
)
@REM =====================================================================
@REM End of Params and Options
@REM =====================================================================
@REM trace call after config
call :_log_trace %_line%
call :_log_trace "Script Variables: _KEEP_FILES=%_KEEP_FILES%"
call :_log_trace "Script Variables: _CREATE_IF_NOT_EXISTS=%_CREATE_IF_NOT_EXISTS%"
call :_log_trace "Runtime Variables: _DEBUG=%_DEBUG%, _DISPLAY_HELP=%_DISPLAY_HELP%"
@REM debug call
call :_log_debug %_line%
call :_log_debug "Current Project: %_PROJECT%"
call :_log_debug "Project Conf: %_PROJECT_CONF%"
call :_log_debug "Project Root Folder: %_PROJECT_ROOT%"
call :_log_debug "Project Keys: %_PROJECT_KEYS:"=%"
call :_log_debug "Project Folder: %_PROJECT_FOLDER%"
call :_log_debug "Project Current Ticket: %_TICKET%"
call :_log_debug %_line%
call :_log_debug "Project Doc Directory=%_PROJECT_DOC_DIR%"
call :_log_debug "Project Log Directory=%_PROJECT_LOG_DIR%"
call :_log_debug "Project Temp Directory=%_PROJECT_TMP_DIR%"
call :_log_debug "Project Source Directory=%_PROJECT_SRC_DIR%"
call :_log_debug "Project Export Directory=%_PROJECT_EXP_DIR%"
call :_log_debug "Project Lib Directory=%_PROJECT_LIB_DIR%"
@REM =====================================================================
@REM continue, so emit one empty line first
@echo.
@REM =====================================================================
@REM all good so far, so...
:_continue
call :_log_info %_line%
call :_log_info "%_SCRIPT%: Starting %_SCRIPT%"
@REM =====================================================================
@REM processing
call :_log_info %_line%
call :_log_info "----- Processing"
call :_log_info %_line%
call :_log_info "Done %_SCRIPT% [%ERRORLEVEL%]"
call :_log_info %_line%
@REM =====================================================================
@REM Skip all SUB ROUTINES
goto:eof
@REM =====================================================================
@REM Function Parse Args (kept here, since script specific)
:parse_args
@REM help
if "%1" == "-h" set "_DISPLAY_HELP=Y" && goto:eof
if "%1" == "-?" set "_DISPLAY_HELP=Y" && goto:eof
if "%1" == "help" set "_DISPLAY_HELP=Y" && goto:eof
@REM debug or trace as option (using LogLevels array)
if "%1" == "-d" set "_LOG_LEVEL=%LogLevels[DEBUG]%"
if "%1" == "debug" set "_LOG_LEVEL=%LogLevels[DEBUG]%"
if "%1" == "-t" set "_LOG_LEVEL=%LogLevels[TRACE]%"
if "%1" == "trace" set "_LOG_LEVEL=%LogLevels[TRACE]%"
@REM param RUN
if "%1" == "-r" set "_PARAM=RUN" && set "_RUN_WHAT=%~2" && set "_RUN_VALUE=%~3"
if "%1" == "run" set "_PARAM=RUN" && set "_RUN_WHAT=%~2" && set "_RUN_VALUE=%~3"
@REM param GET
if "%1" == "-g" set "_PARAM=GET" && set "_GET_WHAT=%~2" && set "_GET_VALUE=%~3"
if "%1" == "get" set "_PARAM=GET" && set "_GET_WHAT=%~2" && set "_GET_VALUE=%~3"
if "%1" == "-s" set "_PARAM=GET" && set "_GET_WHAT=%~2" && set "_GET_VALUE=%~3"
if "%1" == "show" set "_PARAM=GET" && set "_GET_WHAT=%~2" && set "_GET_VALUE=%~3"
@REM param CONFIG
if "%1" == "-c" set "_PARAM=CONFIG" && set _OPTION_VALUE="%~2:%~3+%~4:%~5+%~6:%~7+%~8:%~9"
if "%1" == "config" set "_PARAM=CONFIG" && set _OPTION_VALUE="%~2:%~3+%~4:%~5+%~6:%~7+%~8:%~9"
@REM param MAKE
if "%1" == "-m" set "_PARAM=MAKE" && set "_MAKE_WHAT=%~2" && set "_MAKE_VALUE=%~3" && set "_MAKE_OPT_ARG=%~4"
if "%1" == "make" set "_PARAM=MAKE" && set "_MAKE_WHAT=%~2" && set "_MAKE_VALUE=%~3" && set "_MAKE_OPT_ARG=%~4"
@REM EO Parse Args
shift
if "[%1]"=="[]" goto:eof
goto:parse_args
@REM ==========================================================================
@REM Subroutine Calls to %_FUNCTIONS% and %_UTILS% File
@REM ==========================================================================
@REM framework
:_parse_config_options
%_FUNCTIONS% %*
goto:eof
:_check_option_value
%_FUNCTIONS% %*
goto:eof
:_set_project
%_FUNCTIONS% %*
goto:eof
:_set_ticket
%_FUNCTIONS% %1
goto:eof
:_get-ticket-from-project
%_FUNCTIONS% %1 %2
goto:eof
:_parse_make_options
%_FUNCTIONS% %*
goto:eof
@REM ==========================================================================
@REM Project Conf (script directive: _CURRENT_PROJECT_FILE)
:_write_project_conf
if "%_CREATE_IF_NOT_EXISTS%"=="TRUE" (
@echo _PROJECT=%~1>%_SCRIPTDIR%\%_CURRENT_PROJECT_FILE%
)
goto:eof
@REM ==========================================================================
@REM (ini directives: _CREATE_GITIGNORE for this script)
:_make_gitignore
if "%_CREATE_IF_NOT_EXISTS%"=="TRUE" (
if not exist %~1 (
if "%_CREATE_GITIGNORE%"=="TRUE" (
call :_log_info %_line%
call :_log_info "%_SCRIPT%: Making File %~1"
call :_make_file "%~1"
@echo.>"%~1"
call :_write_gitignore "%~1" "%~2"
)
)
)
goto:eof
@REM ==========================================================================
@REM (ini directives: _PROJECT_SUBFOLDERS and _CREATE_GITIGNORE)
:_write_gitignore
if exist %~1 (
call :_log_debug "%_SCRIPT%: Writing Defaults [%~2] to File %~1"
for %%g in (%~2) do (
@echo.%%g>>"%~1"
)
ATTRIB +H "%~1"
)
goto:eof
@REM ==========================================================================
@REM (ini directives: _PROJECT_SUBFOLDERS and _CREATE_GITIGNORE)
:_create_project_folders
if "%_CREATE_IF_NOT_EXISTS%"=="TRUE" (
for %%g in (%~2) do (
if not exist %~1%%g (
call :_log_info "%_SCRIPT%: Making Directory %~1%%g"
call :_make_folder %~1%%g
if "%_CREATE_GITIGNORE%"=="TRUE" (
call :_log_info "%_SCRIPT%: Making File %~1%%g\%_GITIGNORE%"
call :_make_file %~1%%g\%_GITIGNORE% && (
ATTRIB +H %~1%%g\%_GITIGNORE%
)
)
)
)
)
goto:eof
:_make_project_subfolders
setlocal
set _PRJ_FLDR=%~1
set _PRJ_SUBFLDRS=%~2
call :_log_debug "%_SCRIPT%: Checking PROJECT_FOLDERs .gitignore..."
call :_make_gitignore "%_PRJ_FLDR%%_GITIGNORE%" "%_GITIGNORE_OBJECTS%"
call :_log_debug "%_SCRIPT%: Checking PROJECT_FOLDERs subfolders..."
call :_create_project_folders "%_PRJ_FLDR%" "%_PRJ_SUBFLDRS%"
endlocal
goto:eof
@REM ==========================================================================
@REM utility functions
:_make_folder
%_UTILS% %1
goto:eof
:_make_file
%_UTILS% %1
goto:eof
:_make_help
%_UTILS% %*
goto:eof
:_make_readme
%_UTILS% %*
goto:eof
:_make_htdoc
%_UTILS% %*
goto:eof
@REM ==========================================================================
@REM help functions
:_usage
%_FUNCTIONS% %_SCRIPT%
goto:eof
:_help
%_FUNCTIONS% %_HELP_FILE%
goto:eof
@REM ==========================================================================
@REM helpfiles (defaults: _CREATE_README _CREATE_HTDOC _CREATE_HELP)
:_make_helpfiles
setlocal
set _CONTENT=%~1
set _README_FILE=%~2
set _HTDOC_FILE=%~3
set _HELPFILE=%~4
@REM Helpfile
if not exist "%_HELPFILE%" (
if "%_CREATE_HELP%"=="TRUE" (
call :_log_info "%_SCRIPT%: Making "%_HELPFILE%" file."
call :_make_help %_HELPFILE% %_CONTENT%
)
)
@REM Readme.txt
if not exist "%_README_FILE%" (
if "%_CREATE_README%"=="TRUE" (
call :_log_info "%_SCRIPT%: Making "%_README_FILE%" file."
call :_make_readme %_README_FILE% %_CONTENT% %_HELPFILE% %_HTDOC_FILE%
)
)
@REM Readme.md
if not exist "%_HTDOC_FILE%" (
if "%_CREATE_HTDOC%"=="TRUE" (
call :_log_info "%_SCRIPT%: Making "%_HTDOC_FILE%" file."
call :_make_htdoc %_HTDOC_FILE% %_CONTENT% %_HELPFILE% %_README_FILE%
)
)
endlocal
goto:eof
@REM ==========================================================================
@REM Logging
:_set-log-level
%_FUNCTIONS% %1
goto:eof
:_log_info
%_FUNCTIONS% %*
goto:eof
:_log_warning
%_FUNCTIONS% %*
goto:eof
:_log_trace
%_FUNCTIONS% %*
goto:eof
:_log_debug
%_FUNCTIONS% %*
goto:eof
:_log_error
%_FUNCTIONS% %*
goto:eof
@REM ==========================================================================
@REM EOF
goto:eof
@REM ==========================================================================
@REM close script...
:EOF
@REM ==========================================================================
@REM return to previous directory
popd
endlocal
@REM exit /b %ERRORLEVEL%
%_ex% %ERRORLEVEL%
"@REM oad.ini"
; ==========================================================================
; odev.ini (overwrites defaults if set)
; [Project]
_PROJECT=
_PROJECT_ROOT=U:\git\WWS\_DSD\Projects
; parent folder to your projects (must provide no leading, but a trailing \)
_PROJECT_FOLDER_PREFIX=WWS\
_PROJECT_CONF=.project.conf
_PROJECT_KEYS="JIRA- APEX-,NODE-,ORA-"
_PROJECT_DOC_DIR=DOC
; place sub-subfolders that contain \ at end of string
_PROJECT_SUBFOLDERS=ARC,ARC\Builds,ARC\Sources,ARC\Documents,BLD,DOC,LIB,LOG,SRC,TMP
_GITIGNORE_OBJECTS=ARC,LOG,TMP
; Encoding and Codepage
; [Encoding]
_ENCODING=.AL32UTF8
_CODEPAGE=65001
; [Options]
; Levels: 0=OFF 1=INFO 2=DEBUG 3=TRACE
_LOG_LEVEL=1
; log warnings to console [TRUE|FALSE]
_LOG_WARNINGS=TRUE
; _KEEP_FILES [NONE|ARCHIVE|MOVE]
_KEEP_FILES=ARCHIVE
; Folder and File handling
_CREATE_IF_NOT_EXISTS=TRUE
_CREATE_GITIGNORE=TRUE
_CREATE_README=TRUE
_CREATE_HTDOC=TRUE
_CREATE_HELP=TRUE
"@REM oaddef.cmd"
@REM ==========================================================================
@REM Script Defaults
set _PROJECT=
set _PROJECT_ROOT=C:\%USERPROFILE%\Projects
@REM parent folder to your projects (must provide no leading, but a trailing \)
set _PROJECT_FOLDER_PREFIX=
set _PROJECT_CONF=.project.conf
set _PROJECT_SUBFOLDERS=ARC,ARC\Builds,ARC\Sources,ARC\Documents,BLD,DOC,LIB,LOG,SRC,TMP
set _GITIGNORE_OBJECTS=arc,log,tmp
set _PROJECT_KEYS="JIRA-,APEX-,ORA-"
set _PROJECT_DOC_DIR=DOC
@REM Levels: 0=OFF 1=INFO 2=DEBUG 3=TRACE
set _LOG_LEVEL=1
@REM log warnings to console
set _LOG_WARNINGS=TRUE
@REM Encoding and Codepage
set _ENCODING=.AL32UTF8
set _CODEPAGE=65001
set _FOLDERS=log,tmp,src
set _KEEP_FILES=FALSE
set _CREATE_IF_NOT_EXISTS=FALSE
set _CREATE_GITIGNORE=FALSE
set _CREATE_README=TRUE
set _CREATE_HTDOC=FALSE
set _CREATE_HELP=FALSE
"@REM oadfnc.cmd"
@echo on
setlocal enableextensions
@REM ==========================================================================
@REM Functions
@REM Not to be directly called
exit /b 9009
@REM ---------------------------------------------------------------------
@REM Help
:_help
more %~1
goto:eof
@REM Logging
:_set-log-level
set _THIS=%~n0:_set-log-level
@REM get length of array to reset higher logging levels
call :_get-chr-array-length LogLevels ArraySize
call :_log_trace "%_THIS%: There are %ArraySize% Log Levels."
if %~1 GTR %ArraySize% (
call :_log_warning "%_THIS%: desired Log Level: %~1 will be reset to max level %ArraySize%."
set "_LL=%ArraySize%"
) else (
set "_LL=%~1"
)
setlocal enabledelayedexpansion
set "_LS=!LogSeverities[%_LL%]!"
call :_log_trace "%_THIS%: Current Log Level: %_LL% (!LogSeverities[%_LL%]!)."
endlocal & set "_LOG_LEVEL=%_LL%" & set "_LOG_SEVERITY=%_LS%"
goto:eof
@REM raw log function that processes up to 9 arguments
@REM standard log format for script messages
@REM DATE/TIME SEVERITY ([ERRORLEVEL]) MESSAGE
:_log
setlocal
set _MSG=
if not "%~1." == "." set _MSG=%~1
if not "%~2." == "." set _MSG=%_MSG% %~2
if not "%~3." == "." set _MSG=%_MSG% %~3
if not "%~4." == "." set _MSG=%_MSG% %~4
if not "%~5." == "." set _MSG=%_MSG% %~5
if not "%~5." == "." set _MSG=%_MSG% %~5
if not "%~6." == "." set _MSG=%_MSG% %~6
if not "%~7." == "." set _MSG=%_MSG% %~7
if not "%~8." == "." set _MSG=%_MSG% %~8
if not "%~9." == "." set _MSG=%_MSG% %~9
if not "%_MSG%." == "." @echo.%_MSG%
endlocal
goto:eof
:_log_info
setlocal
if %_LOG_LEVEL% GEQ %LogLevels[INFO]% (
call:_log "%DATE% %TIME:~0,8%" "%_log_info%" %1
) & endlocal
goto:eof
:_log_debug
setlocal
if %_LOG_LEVEL% GEQ %LogLevels[DEBUG]% (
call:_log "%DATE% %TIME:~0,8%" "%_log_debug%" %1
) & endlocal
goto:eof
:_log_trace
setlocal
if %_LOG_LEVEL% GEQ %LogLevels[TRACE]% (
call:_log "%DATE% %TIME:~0,8%" "%_log_trace%" %1
) & endlocal
goto:eof
:_log_warning
setlocal
if "%_LOG_WARNINGS%"=="TRUE" (
if %_LOG_LEVEL% GEQ %LogLevels[INFO]% (
call:_log "%DATE% %TIME:~0,8%" "%_log_warn%" %1
)
) & endlocal
goto:eof
:_log_error
setlocal
@REM setting Errorlevel
if not "%2." == "." (
set _ERR=^[%~2^] ) else (
@REM reset to %_default_error% if no Errorlevel was passed
set _ERR=^[%_default_error%^]
)
if %_LOG_LEVEL% GEQ %LogLevels[INFO]% (
call:_log "%DATE% %TIME:~0,8%" "%_log_error%" %1 "%_ERR%"
) & endlocal
goto:eof
:_usage
@echo.
@echo.Usage: %~1 (options) [params]. Type %~1 -h for more information.
goto:eof
@REM =====================================================================
@REM processing options
@REM parse options
:_parse_config_options
set _THIS=%~n0:_parse_config_options
set _OPTIONS=%1
set _OPT_VAL=%_OPTIONS:"=%
set _OPT_VAL=%_OPT_VAL:+=,%
set _OPT_VAL=%_OPT_VAL:/=%
call :_log_trace "%_THIS%: _OPTIONS=%_OPT_VAL%"
set _PROJECT_SET=%~2
set _TICKET_SET=%~3
set _KEEP_FILES_SET=%~4
set _CREATE_FOLDER_SET=%~5
set _LOG_LEVEL_SET=%~6
setlocal enabledelayedexpansion
for %%g in (%_OPT_VAL%) do (
call :_log_trace "%_THIS%: Check option: %%g"
for /f "tokens=1,2 delims=:" %%x in ('@echo %%g') do (
set _CONFIG_OPTION=%%x
set _CONFIG_VALUE=%%y
if [!_CONFIG_VALUE!]==[] (