2020-01-18 11:38:21 +03:00
|
|
|
/*
|
2021-06-01 10:05:15 +03:00
|
|
|
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
2020-01-18 11:38:21 +03:00
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 11:38:21 +03:00
|
|
|
*/
|
|
|
|
|
2020-05-26 14:52:44 +03:00
|
|
|
#include <AK/LexicalPath.h>
|
2020-08-05 23:42:22 +03:00
|
|
|
#include <LibCore/ArgsParser.h>
|
2019-04-15 14:57:09 +03:00
|
|
|
#include <stdio.h>
|
2021-03-12 19:29:37 +03:00
|
|
|
#include <unistd.h>
|
2019-04-15 14:57:09 +03:00
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
2020-02-18 15:14:55 +03:00
|
|
|
if (pledge("stdio", nullptr) < 0) {
|
|
|
|
perror("pledge");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-06-01 10:05:15 +03:00
|
|
|
StringView path;
|
|
|
|
StringView suffix;
|
2020-08-05 23:42:22 +03:00
|
|
|
|
|
|
|
Core::ArgsParser args_parser;
|
|
|
|
args_parser.add_positional_argument(path, "Path to get basename from", "path");
|
2021-06-01 10:05:15 +03:00
|
|
|
args_parser.add_positional_argument(suffix, "Suffix to strip from name", "suffix", Core::ArgsParser::Required::No);
|
2020-08-05 23:42:22 +03:00
|
|
|
args_parser.parse(argc, argv);
|
|
|
|
|
2021-06-29 17:46:16 +03:00
|
|
|
auto result = LexicalPath::basename(path);
|
2021-06-01 10:13:17 +03:00
|
|
|
|
|
|
|
if (!suffix.is_null() && result.length() != suffix.length() && result.ends_with(suffix))
|
|
|
|
result = result.substring(0, result.length() - suffix.length());
|
|
|
|
|
|
|
|
outln("{}", result);
|
2019-04-15 14:57:09 +03:00
|
|
|
return 0;
|
|
|
|
}
|