Skip to content

Commit

Permalink
Use WithCoord parameter parsing for argv
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pjungkamp committed Jun 16, 2024
1 parent 12dd752 commit 1c8232a
Showing 1 changed file with 8 additions and 34 deletions.
42 changes: 8 additions & 34 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"))
{
Expand All @@ -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);
Expand Down

0 comments on commit 1c8232a

Please sign in to comment.