Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce CLI scripts to one-liners on Windows #30772

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions distribution/src/bin/elasticsearch-cli.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
call "%~dp0elasticsearch-env.bat" || exit /b 1

if defined ES_ADDITIONAL_SOURCES (
for %%a in ("%ES_ADDITIONAL_SOURCES:;=","%") do (
call %~dp0%%a
)
)

for /f "tokens=1*" %%a in ("%*") do (
set main_class=%%a
set arguments=%%b
)

%JAVA% ^
%ES_JAVA_OPTS% ^
-Des.path.home="%ES_HOME%" ^
-Des.path.conf="%ES_PATH_CONF%" ^
-Des.distribution.flavor="%ES_DISTRIBUTION_FLAVOR%" ^
-Des.distribution.type="%ES_DISTRIBUTION_TYPE%" ^
-cp "%ES_CLASSPATH%" ^
%main_class% ^
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems a little weird to be switching between all cap vars and all lowercase vars

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am trying to distinguish between variables set outside the script and within the script that will not leave the script.

%arguments%
15 changes: 4 additions & 11 deletions distribution/src/bin/elasticsearch-keystore.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,10 @@
setlocal enabledelayedexpansion
setlocal enableextensions

call "%~dp0elasticsearch-env.bat" || exit /b 1

%JAVA% ^
%ES_JAVA_OPTS% ^
-Des.path.home="%ES_HOME%" ^
-Des.path.conf="%ES_PATH_CONF%" ^
-Des.distribution.flavor="%ES_DISTRIBUTION_FLAVOR%" ^
-Des.distribution.type="%ES_DISTRIBUTION_TYPE%" ^
-cp "%ES_CLASSPATH%" ^
org.elasticsearch.common.settings.KeyStoreCli ^
%*
call "%~dp0elasticsearch-cli.bat" ^
org.elasticsearch.common.settings.KeyStoreCli ^
%* ^
|| exit /b 1

endlocal
endlocal
13 changes: 3 additions & 10 deletions distribution/src/bin/elasticsearch-plugin.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,10 @@
setlocal enabledelayedexpansion
setlocal enableextensions

call "%~dp0elasticsearch-env.bat" || exit /b 1

%JAVA% ^
%ES_JAVA_OPTS% ^
-Des.path.home="%ES_HOME%" ^
-Des.path.conf="%ES_PATH_CONF%" ^
-Des.distribution.flavor="%ES_DISTRIBUTION_FLAVOR%" ^
-Des.distribution.type="%ES_DISTRIBUTION_TYPE%" ^
-cp "%ES_CLASSPATH%" ^
call "%~dp0elasticsearch-cli.bat" ^
org.elasticsearch.plugins.PluginCli ^
%*
%* ^
|| exit /b 1

endlocal
endlocal
13 changes: 3 additions & 10 deletions distribution/src/bin/elasticsearch-translog.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,10 @@
setlocal enabledelayedexpansion
setlocal enableextensions

call "%~dp0elasticsearch-env.bat" || exit /b 1

%JAVA% ^
%ES_JAVA_OPTS% ^
-Des.path.home="%ES_HOME%" ^
-Des.path.conf="%ES_PATH_CONF%" ^
-Des.distribution.flavor="%ES_DISTRIBUTION_FLAVOR%" ^
-Des.distribution.type="%ES_DISTRIBUTION_TYPE%" ^
-cp "%ES_CLASSPATH%" ^
call "%~dp0elasticsearch-cli.bat" ^
org.elasticsearch.index.translog.TranslogToolCli ^
%*
%* ^
|| exit /b 1

endlocal
endlocal
16 changes: 4 additions & 12 deletions x-pack/plugin/security/src/main/bin/elasticsearch-certgen.bat
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,11 @@ rem you may not use this file except in compliance with the Elastic License.
setlocal enabledelayedexpansion
setlocal enableextensions

call "%~dp0elasticsearch-env.bat" || exit /b 1

call "%~dp0x-pack-security-env.bat" || exit /b 1

%JAVA% ^
%ES_JAVA_OPTS% ^
-Des.path.home="%ES_HOME%" ^
-Des.path.conf="%ES_PATH_CONF%" ^
-Des.distribution.flavor="%ES_DISTRIBUTION_FLAVOR%" ^
-Des.distribution.type="%ES_DISTRIBUTION_TYPE%" ^
-cp "%ES_CLASSPATH%" ^
set ES_ADDITIONAL_SOURCES=x-pack-env;x-pack-security-env
call "%~dp0elasticsearch-cli.bat" ^
org.elasticsearch.xpack.core.ssl.CertificateGenerateTool ^
%*
%* ^
|| exit /b 1

endlocal
endlocal
16 changes: 4 additions & 12 deletions x-pack/plugin/security/src/main/bin/elasticsearch-certutil.bat
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,11 @@ rem you may not use this file except in compliance with the Elastic License.
setlocal enabledelayedexpansion
setlocal enableextensions

call "%~dp0elasticsearch-env.bat" || exit /b 1

call "%~dp0x-pack-security-env.bat" || exit /b 1

%JAVA% ^
%ES_JAVA_OPTS% ^
-Des.path.home="%ES_HOME%" ^
-Des.path.conf="%ES_PATH_CONF%" ^
-Des.distribution.flavor="%ES_DISTRIBUTION_FLAVOR%" ^
-Des.distribution.type="%ES_DISTRIBUTION_TYPE%" ^
-cp "%ES_CLASSPATH%" ^
set ES_ADDITIONAL_SOURCES=x-pack-env;x-pack-security-env
call "%~dp0elasticsearch-cli.bat" ^
org.elasticsearch.xpack.core.ssl.CertificateTool ^
%*
%* ^
|| exit /b 1

endlocal
endlocal
16 changes: 4 additions & 12 deletions x-pack/plugin/security/src/main/bin/elasticsearch-migrate.bat
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,11 @@ rem you may not use this file except in compliance with the Elastic License.
setlocal enabledelayedexpansion
setlocal enableextensions

call "%~dp0elasticsearch-env.bat" || exit /b 1

call "%~dp0x-pack-security-env.bat" || exit /b 1

%JAVA% ^
%ES_JAVA_OPTS% ^
-Des.path.home="%ES_HOME%" ^
-Des.path.conf="%ES_PATH_CONF%" ^
-Des.distribution.flavor="%ES_DISTRIBUTION_FLAVOR%" ^
-Des.distribution.type="%ES_DISTRIBUTION_TYPE%" ^
-cp "%ES_CLASSPATH%" ^
set ES_ADDITIONAL_SOURCES=x-pack-env;x-pack-security-env
call "%~dp0elasticsearch-cli.bat" ^
org.elasticsearch.xpack.security.authc.esnative.ESNativeRealmMigrateTool ^
%*
%* ^
|| exit /b 1

endlocal
endlocal
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,11 @@ rem you may not use this file except in compliance with the Elastic License.
setlocal enabledelayedexpansion
setlocal enableextensions

call "%~dp0elasticsearch-env.bat" || exit /b 1

call "%~dp0x-pack-security-env.bat" || exit /b 1

%JAVA% ^
%ES_JAVA_OPTS% ^
-Des.path.home="%ES_HOME%" ^
-Des.path.conf="%ES_PATH_CONF%" ^
-Des.distribution.flavor="%ES_DISTRIBUTION_FLAVOR%" ^
-Des.distribution.type="%ES_DISTRIBUTION_TYPE%" ^
-cp "%ES_CLASSPATH%" ^
set ES_ADDITIONAL_SOURCES=x-pack-env;x-pack-security-env
call "%~dp0elasticsearch-cli.bat" ^
org.elasticsearch.xpack.security.authc.saml.SamlMetadataCommand ^
%*
%* ^
|| exit /b 1

endlocal
endlocal
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,11 @@ rem you may not use this file except in compliance with the Elastic License.
setlocal enabledelayedexpansion
setlocal enableextensions

call "%~dp0elasticsearch-env.bat" || exit /b 1

call "%~dp0x-pack-security-env.bat" || exit /b 1

%JAVA% ^
%ES_JAVA_OPTS% ^
-Des.path.home="%ES_HOME%" ^
-Des.path.conf="%ES_PATH_CONF%" ^
-Des.distribution.flavor="%ES_DISTRIBUTION_FLAVOR%" ^
-Des.distribution.type="%ES_DISTRIBUTION_TYPE%" ^
-cp "%ES_CLASSPATH%" ^
set ES_ADDITIONAL_SOURCES=x-pack-env;x-pack-security-env
call "%~dp0elasticsearch-cli.bat" ^
org.elasticsearch.xpack.security.authc.esnative.tool.SetupPasswordTool ^
%*
%* ^
|| exit /b 1

endlocal
endlocal
16 changes: 4 additions & 12 deletions x-pack/plugin/security/src/main/bin/elasticsearch-syskeygen.bat
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,11 @@ rem you may not use this file except in compliance with the Elastic License.
setlocal enabledelayedexpansion
setlocal enableextensions

call "%~dp0elasticsearch-env.bat" || exit /b 1

call "%~dp0x-pack-security-env.bat" || exit /b 1

%JAVA% ^
%ES_JAVA_OPTS% ^
-Des.path.home="%ES_HOME%" ^
-Des.path.conf="%ES_PATH_CONF%" ^
-Des.distribution.flavor="%ES_DISTRIBUTION_FLAVOR%" ^
-Des.distribution.type="%ES_DISTRIBUTION_TYPE%" ^
-cp "%ES_CLASSPATH%" ^
set ES_ADDITIONAL_SOURCES=x-pack-env;x-pack-security-env
call "%~dp0elasticsearch-cli.bat" ^
org.elasticsearch.xpack.security.crypto.tool.SystemKeyTool ^
%*
%* ^
|| exit /b 1

endlocal
endlocal
16 changes: 4 additions & 12 deletions x-pack/plugin/security/src/main/bin/elasticsearch-users.bat
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,11 @@ rem you may not use this file except in compliance with the Elastic License.
setlocal enabledelayedexpansion
setlocal enableextensions

call "%~dp0elasticsearch-env.bat" || exit /b 1

call "%~dp0x-pack-security-env.bat" || exit /b 1

%JAVA% ^
%ES_JAVA_OPTS% ^
-Des.path.home="%ES_HOME%" ^
-Des.path.conf="%ES_PATH_CONF%" ^
-Des.distribution.flavor="%ES_DISTRIBUTION_FLAVOR%" ^
-Des.distribution.type="%ES_DISTRIBUTION_TYPE%" ^
-cp "%ES_CLASSPATH%" ^
set ES_ADDITIONAL_SOURCES=x-pack-env;x-pack-security-env
call "%~dp0elasticsearch-cli.bat" ^
org.elasticsearch.xpack.security.authc.file.tool.UsersTool ^
%*
%* ^
|| exit /b 1

endlocal
endlocal
2 changes: 0 additions & 2 deletions x-pack/plugin/security/src/main/bin/x-pack-security-env.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@ rem Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
rem or more contributor license agreements. Licensed under the Elastic License;
rem you may not use this file except in compliance with the Elastic License.

call "%~dp0x-pack-env.bat" || exit /b 1

set ES_CLASSPATH=!ES_CLASSPATH!;!ES_HOME!/modules/x-pack-security/*
16 changes: 4 additions & 12 deletions x-pack/plugin/watcher/src/main/bin/elasticsearch-croneval.bat
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,11 @@ rem you may not use this file except in compliance with the Elastic License.
setlocal enabledelayedexpansion
setlocal enableextensions

call "%~dp0elasticsearch-env.bat" || exit /b 1

call "%~dp0x-pack-watcher-env.bat" || exit /b 1

%JAVA% ^
%ES_JAVA_OPTS% ^
-Des.path.home="%ES_HOME%" ^
-Des.path.conf="%ES_PATH_CONF%" ^
-Des.distribution.flavor="%ES_DISTRIBUTION_FLAVOR%" ^
-Des.distribution.type="%ES_DISTRIBUTION_TYPE%" ^
-cp "%ES_CLASSPATH%" ^
set ES_ADDITIONAL_SOURCES=x-pack-env;x-pack-watcher-env
call "%~dp0elasticsearch-cli.bat" ^
org.elasticsearch.xpack.watcher.trigger.schedule.tool.CronEvalTool ^
%*
%* ^
|| exit /b 1

endlocal
endlocal
2 changes: 0 additions & 2 deletions x-pack/plugin/watcher/src/main/bin/x-pack-watcher-env.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@ rem Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
rem or more contributor license agreements. Licensed under the Elastic License;
rem you may not use this file except in compliance with the Elastic License.

call "%~dp0x-pack-env.bat" || exit /b 1

set ES_CLASSPATH=!ES_CLASSPATH!;!ES_HOME!/modules/x-pack-watcher/*