1
0
mirror of https://github.com/Zygo/bees.git synced 2025-06-16 17:46:16 +02:00

getopt: Add logic to set relative path from $CWD

This commit adds a new option to set relative path output for name_fd().

Signed-off-by: Kai Krakow <kai@kaishome.de>
This commit is contained in:
Kai Krakow
2017-11-12 15:46:41 +01:00
parent 755f16a948
commit 52997936d5

View File

@ -37,6 +37,8 @@ do_cmd_help(char *argv[])
"\t-h, --help\t\tShow this help\n" "\t-h, --help\t\tShow this help\n"
"\t-t, --timestamps\tShow timestamps in log output (default)\n" "\t-t, --timestamps\tShow timestamps in log output (default)\n"
"\t-T, --notimestamps\tOmit timestamps in log output\n" "\t-T, --notimestamps\tOmit timestamps in log output\n"
"\t-p, --absolute-paths\tShow absolute paths (default)\n"
"\t-P, --relative-paths\tShow paths relative to $CWD\n"
"\n" "\n"
"Optional environment variables:\n" "Optional environment variables:\n"
"\tBEESHOME\tPath to hash table and configuration files\n" "\tBEESHOME\tPath to hash table and configuration files\n"
@ -597,6 +599,8 @@ bees_main(int argc, char *argv[])
THROW_CHECK1(invalid_argument, argc, argc >= 0); THROW_CHECK1(invalid_argument, argc, argc >= 0);
string cwd(readlink_or_die("/proc/self/cwd"));
// Defaults // Defaults
bool chatter_prefix_timestamp = true; bool chatter_prefix_timestamp = true;
@ -607,10 +611,12 @@ bees_main(int argc, char *argv[])
static struct option long_options[] = { static struct option long_options[] = {
{ "timestamps", no_argument, NULL, 't' }, { "timestamps", no_argument, NULL, 't' },
{ "notimestamps", no_argument, NULL, 'T' }, { "notimestamps", no_argument, NULL, 'T' },
{ "absolute-paths", no_argument, NULL, 'p' },
{ "relative-paths", no_argument, NULL, 'P' },
{ "help", no_argument, NULL, 'h' } { "help", no_argument, NULL, 'h' }
}; };
c = getopt_long(argc, argv, "Tth", long_options, &option_index); c = getopt_long(argc, argv, "TtPph", long_options, &option_index);
if (-1 == c) { if (-1 == c) {
break; break;
} }
@ -622,6 +628,12 @@ bees_main(int argc, char *argv[])
case 't': case 't':
chatter_prefix_timestamp = true; chatter_prefix_timestamp = true;
break; break;
case 'P':
crucible::set_relative_path(cwd);
break;
case 'p':
crucible::set_relative_path("");
break;
case 'h': case 'h':
do_cmd_help(argv); do_cmd_help(argv);
default: default:
@ -631,6 +643,10 @@ bees_main(int argc, char *argv[])
Chatter::enable_timestamp(chatter_prefix_timestamp); Chatter::enable_timestamp(chatter_prefix_timestamp);
if (!relative_path().empty()) {
BEESLOG("using relative path " << relative_path() << "\n");
}
// Create a context and start crawlers // Create a context and start crawlers
bool did_subscription = false; bool did_subscription = false;
while (optind < argc) { while (optind < argc) {