Show write -force parameter only for commands that support it

When passing a filename parameter to "write", the -force parameter
allows overwriting an existing file.
The "write!" variant (which allows writing files where the current
user does not have write permissions) already implies -force.
All other variants (like write-quit or write-all) do not take a
file parameter.
Hence -force is relevant only for "write".  Let's hide it from the
autoinfo of the other commands.

It's difficult to avoid duplication when constructing the constexpr
SwitchMap because String is not constexpr-enabled.  Today, all our
SwitchMap objects are known at compile time, so we could make SwitchMap
use StringView to work around this. In future we might want to allow
adding switches at runtime, which would need String again to avoid
lifetime issues.
This commit is contained in:
Johannes Altmanninger 2022-08-01 11:36:22 +02:00
parent 348b3f9d9d
commit 7ae31b6778

View File

@ -460,11 +460,19 @@ const CommandDesc force_edit_cmd = {
edit<true>
};
const ParameterDesc write_params{
const ParameterDesc write_params = {
{
{ "sync", { false, "force the synchronization of the file onto the filesystem" } },
{ "method", { true, "explicit writemethod (replace|overwrite)" } },
{ "force", { false, "Allow overwriting existing file with explicit filename" } }
},
ParameterDesc::Flags::SwitchesOnlyAtStart, 0, 1
};
const ParameterDesc write_params_except_force = {
{
{ "sync", { false, "force the synchronization of the file onto the filesystem" } },
{ "method", { true, "explicit writemethod (replace|overwrite)" } },
{ "force", { false, "Allow overwriting existing file with explicit filename" } },
},
ParameterDesc::Flags::SwitchesOnlyAtStart, 0, 1
};
@ -533,7 +541,7 @@ const CommandDesc force_write_cmd = {
"w!",
"write! [<switches>] [<filename>]: write the current buffer to its file "
"or to <filename> if specified, even when the file is write protected",
write_params,
write_params_except_force,
CommandFlags::None,
CommandHelper{},
filename_completer<false>,
@ -568,7 +576,7 @@ const CommandDesc write_all_cmd = {
"wa",
"write-all [<switches>]: write all changed buffers that are associated to a file",
ParameterDesc{
write_params.switches,
write_params_except_force.switches,
ParameterDesc::Flags::None, 0, 0
},
CommandFlags::None,
@ -695,7 +703,7 @@ const CommandDesc write_quit_cmd = {
"wq",
"write-quit [<switches>] [<exit status>]: write current buffer and quit current client. "
"An optional integer parameter can set the client exit status",
write_params,
write_params_except_force,
CommandFlags::None,
CommandHelper{},
CommandCompleter{},
@ -707,7 +715,7 @@ const CommandDesc force_write_quit_cmd = {
"wq!",
"write-quit! [<switches>] [<exit status>] write: current buffer and quit current client, even if other buffers are not saved. "
"An optional integer parameter can set the client exit status",
write_params,
write_params_except_force,
CommandFlags::None,
CommandHelper{},
CommandCompleter{},
@ -719,7 +727,7 @@ const CommandDesc write_all_quit_cmd = {
"waq",
"write-all-quit [<switches>] [<exit status>]: write all buffers associated to a file and quit current client. "
"An optional integer parameter can set the client exit status.",
write_params,
write_params_except_force,
CommandFlags::None,
CommandHelper{},
CommandCompleter{},