feat: add cli addressing from `sha256sum` output
parent
a72b871185
commit
7f889be0db
|
@ -45,8 +45,10 @@ enum Commands {
|
||||||
},
|
},
|
||||||
/// Get the address of a file, attribute or URL.
|
/// Get the address of a file, attribute or URL.
|
||||||
Address {
|
Address {
|
||||||
/// Path to a file.
|
/// Type of input to be addressed
|
||||||
filepath: PathBuf,
|
_type: AddressType,
|
||||||
|
/// Path to a file, hash...
|
||||||
|
input: String,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,6 +59,14 @@ enum OutputFormat {
|
||||||
Raw,
|
Raw,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, PartialEq, Eq, Debug, ValueEnum)]
|
||||||
|
enum AddressType {
|
||||||
|
/// Hash a file and output its address.
|
||||||
|
File,
|
||||||
|
/// Compute an address from the output of `sha256sum`
|
||||||
|
Sha256sum,
|
||||||
|
}
|
||||||
|
|
||||||
fn main() -> anyhow::Result<()> {
|
fn main() -> anyhow::Result<()> {
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
|
@ -117,15 +127,24 @@ fn main() -> anyhow::Result<()> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(Commands::Address { filepath }) => {
|
Some(Commands::Address { _type, input }) => {
|
||||||
debug!("Hashing {:?}...", filepath);
|
let address = match _type {
|
||||||
let fbuffer = FileBuffer::open(&filepath)?;
|
AddressType::File => {
|
||||||
let digest = common::hash(&fbuffer);
|
let filepath = PathBuf::from(input);
|
||||||
trace!("Finished hashing {:?}...", &filepath);
|
debug!("Hashing {:?}...", filepath);
|
||||||
let address = common::Address::Hash(digest);
|
let fbuffer = FileBuffer::open(&filepath)?;
|
||||||
|
let digest = common::hash(&fbuffer);
|
||||||
|
trace!("Finished hashing {:?}...", &filepath);
|
||||||
|
common::Address::Hash(digest)
|
||||||
|
}
|
||||||
|
AddressType::Sha256sum => {
|
||||||
|
let digest = multibase::Base::Base16Lower.decode(input)?;
|
||||||
|
common::Address::Hash(common::Hash(digest))
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
match format {
|
match format {
|
||||||
OutputFormat::Json => todo!(),
|
OutputFormat::Json => println!("\"{}\"", address),
|
||||||
OutputFormat::Tsv | OutputFormat::Raw => println!("{}", address),
|
OutputFormat::Tsv | OutputFormat::Raw => println!("{}", address),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue