Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ use std::fs::{File, metadata};
use std::path::Path;
use std::process::Command;

/// tail a file or execite the fallback command
/// tail a file or execute the fallback command
///
/// Attempts to tail a file. If the file doesn't exist or can't be read,
/// runs the specified fallback command instead passing the specified file.
///
/// Examples:
/// tailor file.txt touch # tail file.txt, or touch file.txt
/// tailor file.txt chmod 755 # tail file.txt, or chmod 755 file.txt
/// tailor config.json cp config.template.json # tail file.txt, or cp config.template.json config.json
/// tailor config.json cp config.template.json # tail config.json, or cp config.template.json config.json
#[derive(Parser, Debug)]
#[command(version, about, long_about, verbatim_doc_comment)]
struct Args {
Expand Down Expand Up @@ -110,7 +110,10 @@ mod tests {

#[test]
fn test_can_tail_file_with_nonexistent_file() {
let result = can_tail_file("/tmp/nonexistent_file_12345").unwrap();
let temp_file = NamedTempFile::new().unwrap();
let file_path = temp_file.path().to_str().unwrap();
std::fs::remove_file(file_path).unwrap();
let result = can_tail_file(file_path).unwrap();
assert!(!result, "Should not be able to tail a nonexistent file");
}

Expand Down Expand Up @@ -212,8 +215,11 @@ mod tests {

#[test]
fn test_main_fails_without_fallback_command() {
let temp_file = NamedTempFile::new().unwrap();
let file_path = temp_file.path().to_str().unwrap();
std::fs::remove_file(file_path).unwrap();
let mut cmd = Command::cargo_bin("tailor").unwrap();
cmd.arg("/tmp/nonexistent_file_12345")
cmd.arg(file_path)
.assert()
.failure()
.stderr(contains("no fallback command"));
Expand Down