mirror of
https://github.com/mawww/kakoune.git
synced 2024-08-17 00:30:26 +03:00
Use WithCoord
parameter parsing for argv
This moves the parameter parsing for the `+<line>:<column>` switch of the commandline to the `ParametersParser`. The position switch now respects the `--` separator between switches and files.
This commit is contained in:
parent
0cdb088981
commit
312002700f
42
src/main.cc
42
src/main.cc
@ -1102,7 +1102,8 @@ int main(int argc, char* argv[])
|
||||
{ "debug", { ArgCompleter{}, "initial debug option value" } },
|
||||
{ "version", { {}, "display kakoune version and exit" } },
|
||||
{ "ro", { {}, "readonly mode" } },
|
||||
{ "help", { {}, "display a help message and quit" } } }
|
||||
{ "help", { {}, "display a help message and quit" } } },
|
||||
ParameterDesc::Flags::WithCoord
|
||||
};
|
||||
|
||||
try
|
||||
@ -1182,32 +1183,8 @@ int main(int argc, char* argv[])
|
||||
parser.get_switch("i").value_or(StringView{}));
|
||||
}
|
||||
|
||||
Vector<StringView> files;
|
||||
Optional<BufferCoord> init_coord;
|
||||
for (auto& name : parser)
|
||||
{
|
||||
if (not name.empty() and name[0_byte] == '+')
|
||||
{
|
||||
if (name == "+" or name == "+:")
|
||||
{
|
||||
client_init = client_init + "; exec gj";
|
||||
continue;
|
||||
}
|
||||
auto colon = find(name, ':');
|
||||
if (auto line = str_to_int_ifp({name.begin()+1, colon}))
|
||||
{
|
||||
init_coord = std::max<BufferCoord>({0,0}, {
|
||||
*line - 1,
|
||||
colon != name.end() ?
|
||||
str_to_int_ifp({colon+1, name.end()}).value_or(1) - 1
|
||||
: 0
|
||||
});
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
files.emplace_back(name);
|
||||
}
|
||||
auto init_coord = parser.get_coord();
|
||||
auto files = parser | gather<Vector<StringView>>();
|
||||
|
||||
if (auto server_session = parser.get_switch("c"))
|
||||
{
|
||||
@ -1219,14 +1196,11 @@ int main(int argc, char* argv[])
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
String new_files;
|
||||
for (auto name : files) {
|
||||
new_files += format("edit '{}'", escape(real_path(name), "'", '\''));
|
||||
if (init_coord) {
|
||||
new_files += format(" {} {}", init_coord->line + 1, init_coord->column + 1);
|
||||
init_coord.reset();
|
||||
}
|
||||
new_files += ";";
|
||||
for (auto file : files)
|
||||
{
|
||||
new_files += format("edit -- '{}'\n", escape(real_path(file), "'", '\''));
|
||||
}
|
||||
|
||||
return run_client(*server_session, {}, new_files + client_init, init_coord, ui_type, false);
|
||||
|
Loading…
Reference in New Issue
Block a user