From e60fae3ee3222916da0c1dfec5eda1a4c26dec5b Mon Sep 17 00:00:00 2001 From: Abid Omar Date: Wed, 10 Apr 2024 02:58:12 +0800 Subject: [PATCH] feat: add a basic CLI for v0 CID --- Cargo.toml | 2 +- README.md | 8 ++++++++ src/main.rs | 16 ++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/main.rs diff --git a/Cargo.toml b/Cargo.toml index 680301d..d65e9a0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ Generate IPFS CIDs (Content Identifiers) from a slice of bytes. keywords = ["ipfs", "cid", "content", "identifier", "hash"] authors = ["Abid Omar "] exclude = ["tests/*", "examples/*", "data/*"] -version = "1.0.0" +version = "2.0.0" edition = "2021" license = "MIT" homepage = "https://github.com/omarabid/ipfs-cid" diff --git a/README.md b/README.md index f6c6495..856b2d1 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,14 @@ QmUBnCzebDwZgkXp9ZkHHKQNfaeWn2Dw8p8vNz4GN4jBLa The file is accessible from IPFS at the same hash: [QmUBnCzebDwZgkXp9ZkHHKQNfaeWn2Dw8p8vNz4GN4jBLa](https://ipfs.io/ipfs/QmUBnCzebDwZgkXp9ZkHHKQNfaeWn2Dw8p8vNz4GN4jBLa) +## CLI + +A basic CLI is avaiable in 2.0.0. It returns v0 CID of the passed file. + +**Usage** + +$ ipfs-cid _file_ + ### License This project is licensed under diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..0cc92b1 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,16 @@ +// ipfs-cid is a tool to generate the CID of a file. +// The CLI is simple and only takes a file path as an argument and prints the CID to STDOUT. +pub fn main() { + let args: Vec = std::env::args().collect(); + if args.len() != 2 { + eprintln!("Usage: ipfs-cid "); + std::process::exit(1); + } + let path = &args[1]; + let file = std::fs::read(path).expect("Failed to read file"); + let cid = ipfs_cid::generate_cid_v0(&file); + match cid { + Ok(cid) => println!("{}", cid), + Err(e) => eprintln!("Failed to generate CID: {}", e), + } +}