Add a fail command to explicitely raise an error

This commit is contained in:
Maxime Coste 2017-10-17 10:02:11 +08:00
parent 431e226fc8
commit 145cf843dd
3 changed files with 19 additions and 0 deletions

View File

@ -725,6 +725,7 @@ command `q!` has to be used).
`:%sh{ echo echo tchou }` will echo tchou in Kakoune, whereas
`:nop %sh{ echo echo tchou }` will not, but both will execute the
shell command.
* `fail <text>`: raise an error, uses <text> as its description
Multiple commands
~~~~~~~~~~~~~~~~~

View File

@ -96,6 +96,9 @@ command *q!* has to be used). Aliases are mentionned below each commands.
*nop*::
does nothing, but arguments will be evaluated (e.g. shell expansion)
*fail* <text>::
raise an error, uses <text> as its description
*declare-option* [-hidden] <type> <name> [<value>]::
*alias* decl +
declare a new option, the -hidden hides the option in completion

View File

@ -2105,6 +2105,20 @@ const CommandDesc rename_session_cmd = {
}
};
const CommandDesc fail_cmd = {
"fail",
nullptr,
"fail [<message>]: raise an error with the given message",
ParameterDesc{},
CommandFlags::None,
CommandHelper{},
CommandCompleter{},
[](const ParametersParser& parser, Context&, const ShellContext&)
{
throw runtime_error(fix_atom_text(join(parser, ' ', false)));
}
};
}
void register_commands()
@ -2166,6 +2180,7 @@ void register_commands()
register_command(select_cmd);
register_command(change_directory_cmd);
register_command(rename_session_cmd);
register_command(fail_cmd);
}
}