-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapache.bat
More file actions
176 lines (148 loc) · 4.26 KB
/
Copy pathapache.bat
File metadata and controls
176 lines (148 loc) · 4.26 KB
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
@rem
@rem Copyright 2020 the original author jacky.eastmoon
@rem All commad module need 3 method :
@rem [command] : Command script
@rem [command]-args : Command script options setting function
@rem [command]-help : Command description
@rem Basically, CLI will not use "--options" to execute function, "--help, -h" is an exception.
@rem But, if need exception, it will need to thinking is common or individual, and need to change BREADCRUMB variable in [command]-args function.
@rem NOTE, batch call [command]-args it could call correct one or call [command] and "-args" is parameter.
@rem
:: ------------------- batch setting -------------------
@rem setting batch file
@rem ref : https://www.tutorialspoint.com/batch_script/batch_script_if_else_statement.htm
@rem ref : https://poychang.github.io/note-batch/
@echo off
setlocal
setlocal enabledelayedexpansion
:: ------------------- declare CLI file variable -------------------
@rem retrieve project name
@rem Ref : https://www.robvanderwoude.com/ntfor.php
@rem Directory = %~dp0
@rem Object Name With Quotations=%0
@rem Object Name Without Quotes=%~0
@rem Bat File Drive = %~d0
@rem Full File Name = %~n0%~x0
@rem File Name Without Extension = %~n0
@rem File Extension = %~x0
set CLI_DIRECTORY=%~dp0
set CLI_FILE=%~n0%~x0
set CLI_FILENAME=%~n0
set CLI_FILEEXTENSION=%~x0
:: ------------------- declare CLI variable -------------------
set BREADCRUMB=cli
set COMMAND=
set COMMAND_BC_AGRS=
set COMMAND_AC_AGRS=
:: ------------------- declare variable -------------------
for %%a in ("%cd%") do (
set PROJECT_NAME=%%~na
)
set PROJECT_ENV=dev
set PROJECT_SSH_USER=somesshuser
set PROJECT_SSH_PASS=somesshpass
:: ------------------- execute script -------------------
call :main %*
goto end
:: ------------------- declare function -------------------
:main (
call :argv-parser %*
call :%BREADCRUMB%-args %COMMAND_BC_AGRS%
call :main-args %COMMAND_BC_AGRS%
IF defined COMMAND (
set BREADCRUMB=%BREADCRUMB%-%COMMAND%
call :main %COMMAND_AC_AGRS%
) else (
call :%BREADCRUMB%
)
goto end
)
:main-args (
for %%p in (%*) do (
if "%%p"=="-h" ( set BREADCRUMB=%BREADCRUMB%-help )
if "%%p"=="--help" ( set BREADCRUMB=%BREADCRUMB%-help )
)
goto end
)
:argv-parser (
set COMMAND=
set COMMAND_BC_AGRS=
set COMMAND_AC_AGRS=
set is_find_cmd=
for %%p in (%*) do (
IF NOT defined is_find_cmd (
echo %%p | findstr /r "\-" >nul 2>&1
if errorlevel 1 (
set COMMAND=%%p
set is_find_cmd=TRUE
) else (
set COMMAND_BC_AGRS=!COMMAND_BC_AGRS! %%p
)
) else (
set COMMAND_AC_AGRS=!COMMAND_AC_AGRS! %%p
)
)
goto end
)
:: ------------------- Main mathod -------------------
:cli (
goto cli-help
)
:cli-args (
goto end
)
:cli-help (
echo This is a Command Line Interface with project %PROJECT_NAME%
echo If not input any command, at default will show HELP
echo.
echo Options:
echo --help, -h Show more information with CLI.
echo.
echo Command:
echo up Start service with docker compose.
echo down Stop service with docker compose.
echo.
echo Run 'cli [COMMAND] --help' for more information on a command.
goto end
)
:: ------------------- Command "start" mathod -------------------
:cli-up (
echo ^> Startup docker container instance
docker rm -f docker-hfs-%PROJECT_NAME%
docker run -di ^
-p 8080:80 ^
-v %cd%\share:/usr/local/apache2/htdocs/ ^
--name docker-hfs-%PROJECT_NAME% ^
httpd:2.4
goto end
)
:cli-up-args (
for %%p in (%*) do (
if "%%p"=="--dev" ( set DEVELOPER=1 )
)
goto end
)
:cli-up-help (
echo Start service with docker compose.
echo.
echo Options:
echo.
goto end
)
:: ------------------- Command "down" mathod -------------------
:cli-down (
@rem Close docker container instance by docker-compose
docker rm -f docker-hfs-%PROJECT_NAME%
goto end
)
:cli-down-args (
goto end
)
:cli-down-help (
echo Close docker container instance by docker-compose.
goto end
)
:: ------------------- End method-------------------
:end (
endlocal
)