Skip to content

Commit

Permalink
Reduce binary size and add directory check for file input
Browse files Browse the repository at this point in the history
- Updated `clap` configuration in Cargo.toml to disable default features, reducing binary size.
- Modified main.rs to check if the provided path is a file, preventing directory input errors.
- Bumped version from 1.0.2 to 1.0.3.
  • Loading branch information
tralwdwd committed Nov 6, 2024
1 parent 4cabfa4 commit 61abf47
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 147 deletions.
144 changes: 1 addition & 143 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[package]
name = "windows-cat"
version = "1.0.2"
version = "1.0.3"
edition = "2021"
description = "unix cat command for windows"
readme = "README.md"
repository = "https://github.com/tralwdwd/windows-cat"
license = "MIT"

[dependencies]
clap = "4.5.20"
clap = {version="4.5.20", default-features=false, features=["std"]}

[[bin]]
name = "cat"
Expand Down
10 changes: 8 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::fs;
use std::path::PathBuf;
use clap::{Arg, Command};

fn main(){
Expand All @@ -12,11 +13,12 @@ fn main(){
.index(1)
)
.get_matches();
let file = matches.get_one::<String>("file")
let file = PathBuf::from(matches.get_one::<String>("file")
.unwrap_or_else(|| {
eprint!("Error: No file specified");
std::process::exit(1);
});
}));
if !file.is_dir(){
match fs::read_to_string(file) {
Ok(contents) => {
// Successfully read the file
Expand All @@ -28,4 +30,8 @@ fn main(){
std::process::exit(1);
}
}
}else{
eprint!("Error: Path is not a file");
std::process::exit(1);
}
}

0 comments on commit 61abf47

Please sign in to comment.