init
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | Cargo.toml | 14 | ||||
| -rw-r--r-- | LICENSE | 21 | ||||
| -rw-r--r-- | README.md | 21 | ||||
| -rw-r--r-- | src/main.rs | 28 |
5 files changed, 86 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..96ef6c0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +Cargo.lock diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..9411625 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "erad" +version = "0.1.0" +edition = "2021" +repository = "https://github.com/bend-n/erad" +keywords = ["cli"] +categories = ["development-tools"] +license = "MIT" +description = "read a file, print the bytes" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +comat = "0.1.3" @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 bendn + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..fc00f81 --- /dev/null +++ b/README.md @@ -0,0 +1,21 @@ +# erad + +fs util for reading the bytes of a file as a array + +## usage + +```bash +erad file +# [0, 5, 221, 4, ...] +``` + +### get + +```bash +cargo install erad +``` + +### see also + +[wrat](https://github.com/bend-n/wrat) + diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..1b5d256 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,28 @@ +#![feature(io_error_more)] +use std::{io::ErrorKind, process::ExitCode}; + +macro_rules! fail { + () => { + fail!("<infile>") + }; + ($usage:literal) => {{ + eprintln!(concat!("usage: erad ", comat::comat!($usage))); + return ExitCode::FAILURE; + }}; +} + +fn main() -> ExitCode { + let Some(out) = std::env::args().nth(1) else { + fail!(); + }; + println!( + "{:?}", + match std::fs::read(out).map_err(|e| e.kind()) { + Err(ErrorKind::IsADirectory) => fail!("<valid {red}{italic}file{reset}>"), + Err(ErrorKind::PermissionDenied) => fail!("<{red}readable filename{reset}>"), + Err(_) => fail!("<{red}infile{reset}>"), + Ok(x) => x, + } + ); + ExitCode::SUCCESS +} |