Skip to content

Commit e7e64a7

Browse files
committed
generate runtime help on the columns available from the metadata
1 parent c14ba0b commit e7e64a7

File tree

2 files changed

+16
-103
lines changed

2 files changed

+16
-103
lines changed

src/field.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,15 @@ macro_rules! fields {
132132
)*
133133
}
134134
}
135+
136+
pub fn get_names_and_descriptions() -> Vec<(Vec<&'static str>, &'static str)> {
137+
vec![
138+
$(
139+
$(#[$variant_attrs])*
140+
(vec![$($text,)*], $($description)?),
141+
)*
142+
]
143+
}
135144
}
136145
};
137146
}

src/main.rs

Lines changed: 7 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use rustyline::DefaultEditor;
2222
use update_informer::{registry, Check};
2323

2424
use crate::config::Config;
25+
use crate::field::Field;
2526
use crate::parser::Parser;
2627
use crate::searcher::Searcher;
2728
use crate::util::{error_exit, error_message};
@@ -337,108 +338,7 @@ Regex syntax:
337338
{}
338339
339340
Column Options:
340-
name Returns the name (with extension) of the file
341-
extension | ext Returns the extension of the file
342-
path Returns the path of the file
343-
abspath Returns the absolute path of the file
344-
directory | dirname | dir Returns the directory of the file
345-
absdir Returns the absolute directory of the file
346-
size Returns the size of the file in bytes
347-
fsize | hsize Returns the size of the file accompanied with the unit
348-
uid Returns the UID of the owner
349-
gid Returns the GID of the owner's group
350-
351-
accessed Returns the time the file was last accessed (YYYY-MM-DD HH:MM:SS)
352-
created Returns the file creation date (YYYY-MM-DD HH:MM:SS)
353-
modified Returns the time the file was last modified (YYYY-MM-DD HH:MM:SS)
354-
355-
is_dir Returns a boolean signifying whether the file path is a directory
356-
is_file Returns a boolean signifying whether the file path is a file
357-
is_symlink Returns a boolean signifying whether the file path is a symlink
358-
is_pipe | is_fifo Returns a boolean signifying whether the file path is a FIFO or pipe file
359-
is_char | is_character Returns a boolean signifying whether the file path is a character device or character special file
360-
is_block Returns a boolean signifying whether the file path is a block or block special file
361-
is_socket Returns a boolean signifying whether the file path is a socket file
362-
is_hidden Returns a boolean signifying whether the file is a hidden file (e.g., files that start with a dot on *nix)
363-
has_xattrs Returns a boolean signifying whether the file has extended attributes
364-
capabilities | caps Returns a string describing Linux capabilities assigned to a file
365-
366-
device (Linux only) Returns the code of device the file is stored on
367-
inode (Linux only) Returns the number of inode
368-
blocks (Linux only) Returns the number of blocks (256 bytes) the file occupies
369-
hardlinks (Linux only) Returns the number of hardlinks of the file
370-
371-
mode Returns the permissions of the owner, group, and everybody (similar to the first field in `ls -la`)
372-
373-
user Returns the name of the owner for this file
374-
user_read Returns a boolean signifying whether the file can be read by the owner
375-
user_write Returns a boolean signifying whether the file can be written by the owner
376-
user_exec Returns a boolean signifying whether the file can be executed by the owner
377-
user_all Returns a boolean signifying whether the file can be fully accessed by the owner
378-
379-
group Returns the name of the owner's group for this file
380-
group_read Returns a boolean signifying whether the file can be read by the owner's group
381-
group_write Returns a boolean signifying whether the file can be written by the owner's group
382-
group_exec Returns a boolean signifying whether the file can be executed by the owner's group
383-
group_all Returns a boolean signifying whether the file can be fully accessed by the group
384-
385-
other_read Returns a boolean signifying whether the file can be read by others
386-
other_write Returns a boolean signifying whether the file can be written by others
387-
other_exec Returns a boolean signifying whether the file can be executed by others
388-
other_all Returns a boolean signifying whether the file can be fully accessed by the others
389-
390-
suid Returns a boolean signifying whether the file permissions have a SUID bit set
391-
sgid Returns a boolean signifying whether the file permissions have a SGID bit set
392-
393-
width Returns the number of pixels along the width of the photo or MP4 file
394-
height Returns the number of pixels along the height of the photo or MP4 file
395-
396-
mime Returns MIME type of the file
397-
is_binary Returns a boolean signifying whether the file has binary contents
398-
is_text Returns a boolean signifying whether the file has text contents
399-
line_count Returns a number of lines in a text file
400-
401-
exif_datetime Returns date and time of taken photo
402-
exif_altitude | exif_alt Returns GPS altitude of taken photo
403-
exif_latitude | exif_lat Returns GPS latitude of taken photo
404-
exif_longitude | exif_lng Returns GPS longitude of taken photo
405-
exif_make Returns name of the camera manufacturer
406-
exif_model Returns camera model
407-
exif_software Returns software name with which the photo was taken
408-
exif_version Returns the version of EXIF metadata
409-
exif_exposure_time | exif_exptime Returns the exposure time of the photo
410-
exif_aperture Returns the aperture of the photo
411-
exif_shutter_speed Returns the shutter speed of the photo
412-
exif_f_number | exif_f_num Returns the F-number of the photo
413-
exif_iso_speed | exif_iso Returns the ISO speed of the photo
414-
exif_focal_length | exif_focal_len Returns the focal length of the photo
415-
exif_lens_make Returns the lens manufacturer of the photo
416-
exif_lens_model Returns the lens model of the photo
417-
418-
mp3_title | title Returns the title of the audio file taken from the file's metadata
419-
mp3_album | album Returns the album name of the audio file taken from the file's metadata
420-
mp3_artist | artist Returns the artist of the audio file taken from the file's metadata
421-
mp3_genre | genre Returns the genre of the audio file taken from the file's metadata
422-
mp3_year Returns the year of the audio file taken from the file's metadata
423-
mp3_freq | freq Returns the sampling rate of audio or video file
424-
mp3_bitrate | bitrate Returns the bitrate of the audio file in kbps
425-
duration Returns the duration of audio file in seconds
426-
427-
is_shebang Returns a boolean signifying whether the file starts with a shebang (#!)
428-
is_empty Returns a boolean signifying whether the file is empty or the directory is empty
429-
is_archive Returns a boolean signifying whether the file is an archival file
430-
is_audio Returns a boolean signifying whether the file is an audio file
431-
is_book Returns a boolean signifying whether the file is a book
432-
is_doc Returns a boolean signifying whether the file is a document
433-
is_font Returns a boolean signifying whether the file is a font file
434-
is_image Returns a boolean signifying whether the file is an image
435-
is_source Returns a boolean signifying whether the file is source code
436-
is_video Returns a boolean signifying whether the file is a video file
437-
438-
sha1 Returns SHA-1 digest of a file
439-
sha2_256 | sha256 Returns SHA2-256 digest of a file
440-
sha2_512 | sha512 Returns SHA2-512 digest of a file
441-
sha3_512 | sha3 Returns SHA-3 digest of a file
341+
{}
442342
443343
Functions:
444344
Aggregate:
@@ -534,5 +434,9 @@ Format:
534434
csv Outputs each file with its column value(s) on a line with each column value delimited by a comma
535435
json Outputs a JSON array with JSON objects holding the column value(s) of each file
536436
html Outputs HTML document with table
537-
", Cyan.underline().paint("https://docs.rs/regex/1.10.2/regex/#syntax"));
437+
", Cyan.underline().paint("https://docs.rs/regex/1.10.2/regex/#syntax"),
438+
Field::get_names_and_descriptions().iter()
439+
.map(|(names, description)| names.join(" | ").to_string() + " ".repeat(if 32 > names.join(" | ").to_string().len() { 32 - names.join(" | ").to_string().len() } else { 1 }).as_str() + description)
440+
.collect::<Vec<_>>().join("\n ")
441+
);
538442
}

0 commit comments

Comments
 (0)