summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohannes Altmanninger <aclopte@gmail.com>2022-08-01 11:36:22 +0200
committerJohannes Altmanninger <aclopte@gmail.com>2022-08-28 09:28:06 +0200
commit7ae31b6778fdf8129f4ccc0045e27c8389e53e18 (patch)
tree61911b96ab17d5347da3e0f803646b86e847b176 /src
parent348b3f9d9d2a72017a320283698e8e06d3712aea (diff)
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.
Diffstat (limited to 'src')
-rw-r--r--src/commands.cc22
1 files 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<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{},