From a9ccbc28f9150bd87c80e01424872a158afdb981 Mon Sep 17 00:00:00 2001 From: nick black Date: Thu, 31 Dec 2020 02:31:28 -0500 Subject: [PATCH] ncls: support -V/--version #1266 --- doc/man/man1/ncls.1.md | 4 +++- src/ls/main.cpp | 17 +++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/doc/man/man1/ncls.1.md b/doc/man/man1/ncls.1.md index cf4e4a510..e30b6ea49 100644 --- a/doc/man/man1/ncls.1.md +++ b/doc/man/man1/ncls.1.md @@ -8,7 +8,7 @@ ncls - List paths with rendering of multimedia # SYNOPSIS -**ncls** [**-h**|**--help**] [**-d**] [**-l**] [**-L**] [**-R**] [**-a|**--align** ***type***] [ paths ] +**ncls** [**-h**|**--help**] [**-V**|**--version**] [**-d**] [**-l**] [**-L**] [**-R**] [**-a|**--align** ***type***] [ paths ] # DESCRIPTION @@ -25,6 +25,8 @@ ncls - List paths with rendering of multimedia **-R**: list subdirectories recursively. +**-V**|**--version**: Print version information, and exit with success. + **-h**|**--help**: Print help information, and exit with success. **-a**|**--align** ***type***: Align images on **left**, **center**, or **right**. diff --git a/src/ls/main.cpp b/src/ls/main.cpp index aed6f329e..53a3bea3b 100644 --- a/src/ls/main.cpp +++ b/src/ls/main.cpp @@ -19,13 +19,14 @@ #endif void usage(std::ostream& os, const char* name, int code){ - os << "usage: " << name << " -h | [ -lLR ] [ --align type ] paths...\n"; + os << "usage: " << name << " -h | -V | [ -lLR ] [ --align type ] paths...\n"; os << " -d: list directories themselves, not their contents\n"; os << " -l: use a long listing format\n"; os << " -L: dereference symlink arguments\n"; os << " -R: list subdirectories recursively\n"; os << " -a|--align type: one of left, right, or center\n"; os << " -h: print usage information\n"; + os << " -V: print version information\n"; os << std::flush; exit(code); } @@ -84,7 +85,7 @@ int handle_dir(int dirfd, std::filesystem::path& pdir, const char* p, const stru } DIR* dir = fdopendir(newdir); auto subdir = pdir / p; - if(dir == NULL){ + if(dir == nullptr){ std::cerr << "Error opening " << p << ": " << strerror(errno) << std::endl; close(newdir); return -1; @@ -181,13 +182,17 @@ int main(int argc, char* const * argv){ bool dereflinks = false; ncalign_e alignment = NCALIGN_RIGHT; const struct option opts[] = { - { "align", 1, NULL, 'a' }, - { "help", 0, NULL, 'h' }, - { NULL, 0, NULL, 0 }, + { "align", 1, nullptr, 'a' }, + { "help", 0, nullptr, 'h' }, + { "version", 0, nullptr, 'V' }, + { nullptr, 0, nullptr, 0 }, }; int c, lidx; - while((c = getopt_long(argc, argv, "a:dhlLR", opts, &lidx)) != -1){ + while((c = getopt_long(argc, argv, "Va:dhlLR", opts, &lidx)) != -1){ switch(c){ + case 'V': + printf("ncls version %s\n", notcurses_version()); + exit(EXIT_SUCCESS); case 'a': if(strcasecmp(optarg, "left") == 0){ alignment = NCALIGN_LEFT;