mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
CLI: Added handling of argv[0] when it is not named 'timew'
This commit is contained in:
parent
e09d4e8625
commit
f2407dfbe7
1 changed files with 17 additions and 0 deletions
17
src/CLI.cpp
17
src/CLI.cpp
|
@ -144,6 +144,11 @@ void CLI::add (const std::string& argument)
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Arg0 is the first argument, which is the name and potentially a relative or
|
||||
// absolute path to the invoked binary.
|
||||
//
|
||||
// The binary name is 'timew', but if the binary is reported as 'foo' then it
|
||||
// was invoked via symbolic link, in which case capture the first argument as
|
||||
// 'foo'. This should allow any command/extension to do this.
|
||||
//
|
||||
void CLI::handleArg0 ()
|
||||
{
|
||||
// Capture arg0 separately, because it is the command that was run, and could
|
||||
|
@ -152,6 +157,18 @@ void CLI::handleArg0 ()
|
|||
A2 a (raw, Lexer::Type::word);
|
||||
a.tag ("BINARY");
|
||||
|
||||
std::string basename = "timew";
|
||||
auto slash = raw.rfind ('/');
|
||||
if (slash != std::string::npos)
|
||||
basename = raw.substr (slash + 1);
|
||||
|
||||
a.attribute ("basename", basename);
|
||||
if (basename != "timew")
|
||||
{
|
||||
A2 cal (basename, Lexer::Type::word);
|
||||
_args.push_back (cal);
|
||||
}
|
||||
|
||||
_args.push_back (a);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue