forked from simonwhitaker/gibo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dobo.bat
201 lines (153 loc) · 5.27 KB
/
dobo.bat
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
@rem #!/dos/rocks!
@setlocal EnableDelayedExpansion
@echo off
rem Script for easily accessing dockerignore boilerplates from
rem https://github.com/KeisukeYamashita/dobo
rem
rem Change log
rem v1.0 15-Feb-2021 First public release
goto :setup
:version
echo %basename% 1.0 by KeisukeYamashita ^<[email protected]^>
echo https://github.com/KeisukeYamashita/dobo
goto :eof
:usage
call :version
echo.
echo Fetches dockerignore boilerplates from github.com/KeisukeYamashita/dockerignore
echo.
echo Usage:
echo %basename% [command]
echo.
echo Example:
echo %basename% dump Python NotepadPP ^>^> .dockerignore
echo.
echo Options:
echo dump expr... Dump boilerplate(s) to stdout
echo help Display this help text
echo list List available boilerplates
echo root Show the directory where gibo stores its boilerplates
echo search expr Search inside boilerplates for expr
echo update Update list of available boilerplates
echo version Display current script version
goto :eof
:setup
set "basename=%~n0"
set "baseext=%~x0"
set "basepath=%~dp0"
set "__cloned="
set "dumping="
set "remote_repo=https://github.com/KeisukeYamashita/dockerignore.git"
rem Allow using the `DOBO_BOILERPLATES` system envar
rem for specifying the boilerplates directory.
if defined DOBO_BOILERPLATES set "local_repo=%DOBO_BOILERPLATES%"
if not defined DOBO_BOILERPLATES set "local_repo=%AppData%\.dockerignore-boilerplates"
rem No args passed in, so show usage.
if "%~1"=="" call :usage && goto :end
:parse
rem Parse comand-line options.
if "%~1"=="" goto :end
set a=%~1
rem The batch file's equivalent 'Sanity check' is that any
rem options (-, --, and / for Windows) are executed then
rem the batch file exits, ignoring any other commands, such
rem as Python, etc.
if /i "%a%"=="help" call :usage & goto :end
if /i "%a%"=="/?" call :usage & goto :end
if /i "%a%"=="version" call :version & goto :end
if /i "%a%"=="/v" call :version & goto :end
if /i "%a%"=="list" call :list "%~2" & goto :end
if /i "%a%"=="root" call :root & goto :end
if /i "%a%"=="search" call :search "%~2" & goto :end
if /i "%a%"=="update" call :update & goto :end
if /i "%a%"=="dump" set "dumping=1" & shift & goto :parse
if defined dumping call :dump "%a%" & shift & goto :parse
goto :invalid_argument "%a%"
:end
@endlocal && exit /B 0
:invalid_argument "arg"
echo Invalid argument: %~1
echo Did you mean:
rem Is there a .dockerignore file?
set "_foundfile="
if exist "%local_repo%\%~1.dockerignore" set "_foundfile=yes"
if exist "%local_repo%\Global\%~1.dockerignore" set "_foundfile=yes"
if defined _foundfile (
echo `%basename% dump %*`
echo `%basename% list %*`
)
rem Did the user mean to search within .dockerignore files?
echo `%basename% search %*`
endlocal && exit /B 1
:clone [--silently]
if "%~1"=="--silently" ( set "opt=-q" ) else ( set "opt=" )
git clone %opt% "%remote_repo%" "%local_repo%"
goto :eof
:init [--silently]
if not exist "%local_repo%\.git" set "__cloned=yes" && call :clone "%~1"
goto :eof
:list
call :init
echo === Languages ===
echo.
for /f %%G in ('dir /b /on "%local_repo%\*%~1*.dockerignore"') do (
echo %%~nG
)
echo.
echo === Global ===
echo.
for /f %%G in ('dir /b /on "%local_repo%\Global\*%~1*.dockerignore"') do (
echo %%~nG
)
goto :eof
:root
echo %local_repo%
goto :eof
:search
if "%~1"=="" echo %basename%: missing search expr.. && goto :eof
call :init
rem `findstr` options:
rem /R Uses search strings as regular expressions.
rem /S Searches for matching files in the current directory and all
rem subdirectories.
rem /I Specifies that the search is not to be case-sensitive.
rem /N Prints the line number before each line that matches.
rem /P Skip files with non-printable characters.
rem /A:attr Specifies color attribute with two hex digits. See "color /?"
rem strings Text to be searched for.
rem [drive:][path]filename
rem Specifies a file or files to search.
pushd "%local_repo%"
findstr /S /R /I /N /P /A:03 "%~1" *.dockerignore
popd
goto :eof
:update
call :init
rem If the repo was just cloned, don't perform a `pull`
if not defined __cloned (
echo updating..
pushd "%local_repo%"
git pull -q --ff origin master
popd
)
goto :eof
:dump
call :init --silently
set "language_file=%local_repo%\%~1.dockerignore"
set "global_file=%local_repo%\Global\%~1.dockerignore"
if exist "%language_file%" (
echo ### %~1
echo.
type "%language_file%"
echo.
echo.
) else if exist "%global_file%" (
echo ### %~1
echo.
type "%global_file%"
echo.
echo.
) else (
echo Unknown argument: %~1
)
goto :eof