Merge remote-tracking branch 'lenormf/kill-clients-exit-code'

This commit is contained in:
Maxime Coste 2018-07-19 18:42:22 +10:00
commit 56a5dc66ff

View File

@ -434,30 +434,44 @@ static void ensure_all_buffers_are_saved()
throw runtime_error(message); throw runtime_error(message);
} }
template<bool force>
void kill(const ParametersParser& parser, Context& context, const ShellContext&)
{
auto& client_manager = ClientManager::instance();
if (not force and client_manager.count() == 1)
ensure_all_buffers_are_saved();
const int status = parser.positional_count() > 0 ? str_to_int(parser[0]) : 0;
while (not client_manager.empty())
client_manager.remove_client(**client_manager.begin(), true, status);
throw kill_session{};
}
const CommandDesc kill_cmd = { const CommandDesc kill_cmd = {
"kill", "kill",
nullptr, nullptr,
"kill current session, quit all clients and server", "kill [exit_code]: terminate the current session, the server and all clients connected"
no_params, "; the given integer will be used as exit code by the server and client processes",
{ {}, ParameterDesc::Flags::SwitchesAsPositional, 0, 1 },
CommandFlags::None, CommandFlags::None,
CommandHelper{}, CommandHelper{},
CommandCompleter{}, CommandCompleter{},
[](const ParametersParser&, Context&, const ShellContext&){ kill<false>
ensure_all_buffers_are_saved();
throw kill_session{};
}
}; };
const CommandDesc force_kill_cmd = { const CommandDesc force_kill_cmd = {
"kill!", "kill!",
nullptr, nullptr,
"kill current session, quit all clients and server, do not check for unsaved buffers", "kill [exit_code]: force the termination of the current session, the server and all clients connected"
no_params, "; the given integer will be used as exit code by the server and client processes",
{ {}, ParameterDesc::Flags::SwitchesAsPositional, 0, 1 },
CommandFlags::None, CommandFlags::None,
CommandHelper{}, CommandHelper{},
CommandCompleter{}, CommandCompleter{},
[](const ParametersParser&, Context&, const ShellContext&){ throw kill_session{}; } kill<true>
}; };
template<bool force> template<bool force>