From 348b3f9d9d2a72017a320283698e8e06d3712aea Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Mon, 1 Aug 2022 10:20:30 +0200 Subject: [PATCH 1/2] Fix synopsis of write-quit commands Like other write commands, these support the -method switch, so indicate that in the synopsis. --- src/commands.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/commands.cc b/src/commands.cc index 6715fd05..bc6ff514 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -693,7 +693,7 @@ void write_quit(const ParametersParser& parser, Context& context, const CommandDesc write_quit_cmd = { "write-quit", "wq", - "write-quit [-sync] []: write current buffer and quit current client. " + "write-quit [] []: write current buffer and quit current client. " "An optional integer parameter can set the client exit status", write_params, CommandFlags::None, @@ -705,7 +705,7 @@ const CommandDesc write_quit_cmd = { const CommandDesc force_write_quit_cmd = { "write-quit!", "wq!", - "write-quit! [-sync] [] write: current buffer and quit current client, even if other buffers are not saved. " + "write-quit! [] [] 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, CommandFlags::None, @@ -717,7 +717,7 @@ const CommandDesc force_write_quit_cmd = { const CommandDesc write_all_quit_cmd = { "write-all-quit", "waq", - "write-all-quit [-sync] []: write all buffers associated to a file and quit current client. " + "write-all-quit [] []: write all buffers associated to a file and quit current client. " "An optional integer parameter can set the client exit status.", write_params, CommandFlags::None, From 7ae31b6778fdf8129f4ccc0045e27c8389e53e18 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Mon, 1 Aug 2022 11:36:22 +0200 Subject: [PATCH 2/2] 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. --- src/commands.cc | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/commands.cc b/src/commands.cc index bc6ff514..b6d031ea 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -460,11 +460,19 @@ const CommandDesc force_edit_cmd = { edit }; -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! [] []: write the current buffer to its file " "or to if specified, even when the file is write protected", - write_params, + write_params_except_force, CommandFlags::None, CommandHelper{}, filename_completer, @@ -568,7 +576,7 @@ const CommandDesc write_all_cmd = { "wa", "write-all []: 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 [] []: 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! [] [] 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 [] []: 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{},