1个不稳定版本
0.1.0 | 2023年10月17日 |
---|
#46 in #filesize
20KB
307 代码行
摘要
此代码实现了一个Rust程序,该程序在指定的目录中查找大于100MB的文件,如果没有给出文件路径,则在整个文件系统中查找。它使用clap
库进行命令行参数解析,并使用std
库进行文件大小计算。
使用示例
// Run the program with a specific directory path
$ ./sizer -p /path/to/directory
// Run the program without specifying a directory path (searches the whole file system)
$ ./sizer
// Run the program with a specific directory path and custom file size threshold
$ ./sizer -p /path/to/directory -s 200
代码分析
输入
matches
:一个包含解析后的命令行参数的clap::ArgMatches
对象。
流程
- 初始化日志记录器以进行日志记录。
- 使用
clap
解析命令行参数以获取matches
对象。 - 从
matches
对象中获取path
参数的值。 - 如果提供了
path
值,将其转换为PathBuf
对象,并将其分配给home_dir
。 - 从
matches
对象中获取size
参数的值。 - 如果提供了
size
值,将其作为Option<&String>
分配给size
。 - 如果提供了
path
值,使用home_dir
和size
作为参数调用sizer
库中的entry
函数。 - 如果没有提供
path
值,为根目录("/")创建一个PathBuf
对象,并将其分配给root_dir
。 - 使用
root_dir
和size
作为参数调用sizer
库中的entry
函数。
输出
无。该函数根据提供的命令行参数执行文件大小计算和日志记录。
依赖关系
~4–13MB
~146K SLoC