Summary
Enhance the existing CLI structure with comprehensive argument parsing, robust error handling, and additional command-line options to make StringyMcStringFace more flexible and user-friendly.
Background
The basic CLI structure has been established in src/main.rs using clap's derive API. Currently, it accepts a single input file argument. However, to make the tool production-ready, we need to expand the CLI with additional options and implement proper error handling for various failure scenarios.
Current State
- ✅ Basic clap integration with derive API (v4.5.48)
- ✅ Single file input argument
- ✅ Help text and version information
- ❌ No output file/format options
- ❌ Limited error handling for file operations
- ❌ No verbosity or logging controls
- ❌ No filtering or configuration options
Proposed Solution
1. Additional CLI Arguments
Add the following arguments to the Cli struct:
#[derive(Parser)]
#[command(name = "stringy")]
#[command(about = "Extract meaningful strings from binary files")]
#[command(version)]
struct Cli {
/// Input binary file to analyze
#[arg(value_name = "FILE")]
input: PathBuf,
/// Output file path (defaults to stdout)
#[arg(short, long, value_name = "FILE")]
output: Option<PathBuf>,
/// Output format: json, text, csv
#[arg(short = 'f', long, default_value = "text")]
format: String,
/// Minimum string length to extract
#[arg(short = 'n', long, default_value = "4")]
min_length: usize,
/// Verbose output
#[arg(short, long, action = clap::ArgAction::Count)]
verbose: u8,
}
2. Error Handling
Implement comprehensive error handling for:
- File not found: Provide clear error message with file path
- Permission denied: Inform user about access issues
- Invalid file format: Detect and report unsupported file types
- Output write failures: Handle disk full, permission issues
- Invalid arguments: Validate min_length, format options, etc.
Create a custom error type using thiserror (already in dependencies):
#[derive(Debug, thiserror::Error)]
enum CliError {
#[error("Failed to read input file '{0}': {1}")]
InputFileError(PathBuf, std::io::Error),
#[error("Failed to write output file '{0}': {1}")]
OutputFileError(PathBuf, std::io::Error),
#[error("Unsupported output format: {0}. Supported formats: json, text, csv")]
UnsupportedFormat(String),
#[error("Invalid minimum length: {0}. Must be between 1 and 1024")]
InvalidMinLength(usize),
}
3. Input Validation
Add validation logic in main():
- Check if input file exists and is readable
- Validate output format against supported formats
- Validate min_length is within reasonable bounds (1-1024)
- Ensure output path is writable (if specified)
4. Verbosity Handling
Implement basic logging based on verbose flag:
-v: Info level (show file being processed)
-vv: Debug level (show detailed extraction info)
-vvv: Trace level (show all internal operations)
Acceptance Criteria
Testing Checklist
Implementation Notes
- Use clap's built-in validation features where possible (value_parser)
- Consider using
clap::ValueEnum for the format argument for type-safe parsing
- Keep error messages user-friendly and actionable
- Consider adding color to error output using a crate like
colored
References
Task-ID
stringy-analyzer/basic-cli-structure
Requirements
7.7
Summary
Enhance the existing CLI structure with comprehensive argument parsing, robust error handling, and additional command-line options to make StringyMcStringFace more flexible and user-friendly.
Background
The basic CLI structure has been established in
src/main.rsusing clap's derive API. Currently, it accepts a single input file argument. However, to make the tool production-ready, we need to expand the CLI with additional options and implement proper error handling for various failure scenarios.Current State
Proposed Solution
1. Additional CLI Arguments
Add the following arguments to the
Clistruct:2. Error Handling
Implement comprehensive error handling for:
Create a custom error type using
thiserror(already in dependencies):3. Input Validation
Add validation logic in
main():4. Verbosity Handling
Implement basic logging based on verbose flag:
-v: Info level (show file being processed)-vv: Debug level (show detailed extraction info)-vvv: Trace level (show all internal operations)Acceptance Criteria
-o/--outputflag-f/--formatflag (json, text, csv)-n/--min-lengthflag-v/-vv/-vvvTesting Checklist
--helpoutput--versionoutputImplementation Notes
clap::ValueEnumfor the format argument for type-safe parsingcoloredReferences
Task-ID
stringy-analyzer/basic-cli-structure
Requirements
7.7