feat(version): unverbose ":version", ":verbose version" #24195

Problem:
`nvim -v` and `:version` prints system vimrc, fallback files, and compilation
info by default, which most people don't care about and just clutters up the
output.

Solution:
Omit extra info unless 'verbose' is set.
This commit is contained in:
Justin M. Keyes
2023-07-01 03:45:45 -07:00
committed by GitHub
parent ba8f19ebb6
commit 43ded8d358
3 changed files with 44 additions and 21 deletions

View File

@ -66,6 +66,8 @@ set(ENV{SYSTEM_NAME} ${CMAKE_HOST_SYSTEM_NAME}) # used by test/helpers.lua.
set(ENV{DEPS_INSTALL_DIR} ${DEPS_INSTALL_DIR}) # used by test/busted_runner.lua set(ENV{DEPS_INSTALL_DIR} ${DEPS_INSTALL_DIR}) # used by test/busted_runner.lua
execute_process( execute_process(
# Note: because of "-ll" (low-level interpreter mode), some modules like
# _editor.lua are not loaded.
COMMAND ${NVIM_PRG} -ll ${WORKING_DIR}/test/busted_runner.lua -v -o test.busted.outputHandlers.${BUSTED_OUTPUT_TYPE} COMMAND ${NVIM_PRG} -ll ${WORKING_DIR}/test/busted_runner.lua -v -o test.busted.outputHandlers.${BUSTED_OUTPUT_TYPE}
--lazy --helper=${TEST_DIR}/${TEST_TYPE}/preload.lua --lazy --helper=${TEST_DIR}/${TEST_TYPE}/preload.lua
--lpath=${BUILD_DIR}/?.lua --lpath=${BUILD_DIR}/?.lua

View File

@ -2700,33 +2700,39 @@ void list_version(void)
msg(longVersion); msg(longVersion);
msg(version_buildtype); msg(version_buildtype);
list_lua_version(); list_lua_version();
#ifndef NDEBUG
msg(version_cflags);
#endif
version_msg("\n\n"); if (p_verbose > 0) {
#ifndef NDEBUG
msg(version_cflags);
#endif
version_msg("\n\n");
#ifdef SYS_VIMRC_FILE #ifdef SYS_VIMRC_FILE
version_msg(_(" system vimrc file: \"")); version_msg(_(" system vimrc file: \""));
version_msg(SYS_VIMRC_FILE); version_msg(SYS_VIMRC_FILE);
version_msg("\"\n"); version_msg("\"\n");
#endif // ifdef SYS_VIMRC_FILE #endif
#ifdef HAVE_PATHDEF #ifdef HAVE_PATHDEF
if (*default_vim_dir != NUL) {
version_msg(_(" fall-back for $VIM: \""));
version_msg(default_vim_dir);
version_msg("\"\n");
}
if (*default_vim_dir != NUL) { if (*default_vimruntime_dir != NUL) {
version_msg(_(" fall-back for $VIM: \"")); version_msg(_(" f-b for $VIMRUNTIME: \""));
version_msg(default_vim_dir); version_msg(default_vimruntime_dir);
version_msg("\"\n"); version_msg("\"\n");
}
#endif
} }
if (*default_vimruntime_dir != NUL) { version_msg(p_verbose > 0
version_msg(_(" f-b for $VIMRUNTIME: \"")); ? "\nRun :checkhealth for more info"
version_msg(default_vimruntime_dir); : (starting
version_msg("\"\n"); ? "\nRun \"nvim -V1 -v\" for more info"
} : "\nRun \":verbose version\" for more info"));
#endif // ifdef HAVE_PATHDEF
version_msg("\nRun :checkhealth for more info");
} }
/// Show the intro message when not editing a file. /// Show the intro message when not editing a file.

View File

@ -3,6 +3,7 @@ local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen') local Screen = require('test.functional.ui.screen')
local eq = helpers.eq local eq = helpers.eq
local matches = helpers.matches
local feed = helpers.feed local feed = helpers.feed
local eval = helpers.eval local eval = helpers.eval
local clear = helpers.clear local clear = helpers.clear
@ -12,21 +13,24 @@ local write_file = helpers.write_file
local is_os = helpers.is_os local is_os = helpers.is_os
local skip = helpers.skip local skip = helpers.skip
describe('Command-line option', function() describe('command-line option', function()
describe('-s', function() describe('-s', function()
local fname = 'Xtest-functional-core-main-s' local fname = 'Xtest-functional-core-main-s'
local fname_2 = fname .. '.2' local fname_2 = fname .. '.2'
local nonexistent_fname = fname .. '.nonexistent' local nonexistent_fname = fname .. '.nonexistent'
local dollar_fname = '$' .. fname local dollar_fname = '$' .. fname
before_each(function() before_each(function()
clear() clear()
os.remove(fname) os.remove(fname)
os.remove(dollar_fname) os.remove(dollar_fname)
end) end)
after_each(function() after_each(function()
os.remove(fname) os.remove(fname)
os.remove(dollar_fname) os.remove(dollar_fname)
end) end)
it('treats - as stdin', function() it('treats - as stdin', function()
eq(nil, luv.fs_stat(fname)) eq(nil, luv.fs_stat(fname))
funcs.system( funcs.system(
@ -38,6 +42,7 @@ describe('Command-line option', function()
local attrs = luv.fs_stat(fname) local attrs = luv.fs_stat(fname)
eq(#('42\n'), attrs.size) eq(#('42\n'), attrs.size)
end) end)
it('does not expand $VAR', function() it('does not expand $VAR', function()
eq(nil, luv.fs_stat(fname)) eq(nil, luv.fs_stat(fname))
eq(true, not not dollar_fname:find('%$%w+')) eq(true, not not dollar_fname:find('%$%w+'))
@ -50,6 +55,7 @@ describe('Command-line option', function()
local attrs = luv.fs_stat(fname) local attrs = luv.fs_stat(fname)
eq(#('100500\n'), attrs.size) eq(#('100500\n'), attrs.size)
end) end)
it('does not crash after reading from stdin in non-headless mode', function() it('does not crash after reading from stdin in non-headless mode', function()
skip(is_os('win')) skip(is_os('win'))
local screen = Screen.new(40, 8) local screen = Screen.new(40, 8)
@ -100,6 +106,7 @@ describe('Command-line option', function()
]]) ]])
]=] ]=]
end) end)
it('errors out when trying to use nonexistent file with -s', function() it('errors out when trying to use nonexistent file with -s', function()
eq( eq(
'Cannot open for reading: "'..nonexistent_fname..'": no such file or directory\n', 'Cannot open for reading: "'..nonexistent_fname..'": no such file or directory\n',
@ -110,6 +117,7 @@ describe('Command-line option', function()
'-s', nonexistent_fname})) '-s', nonexistent_fname}))
eq(2, eval('v:shell_error')) eq(2, eval('v:shell_error'))
end) end)
it('errors out when trying to use -s twice', function() it('errors out when trying to use -s twice', function()
write_file(fname, ':call setline(1, "1")\n:wqall!\n') write_file(fname, ':call setline(1, "1")\n:wqall!\n')
write_file(dollar_fname, ':call setline(1, "2")\n:wqall!\n') write_file(dollar_fname, ':call setline(1, "2")\n:wqall!\n')
@ -124,4 +132,11 @@ describe('Command-line option', function()
eq(nil, luv.fs_stat(fname_2)) eq(nil, luv.fs_stat(fname_2))
end) end)
end) end)
it('nvim -v, :version', function()
matches('Run ":verbose version"', funcs.execute(':version'))
matches('Compilation: .*Run :checkhealth', funcs.execute(':verbose version'))
matches('Run "nvim %-V1 %-v"', funcs.system({nvim_prog_abs(), '-v'}))
matches('Compilation: .*Run :checkhealth', funcs.system({nvim_prog_abs(), '-V1', '-v'}))
end)
end) end)