From 0e190a6b33f1c7a22361981d70c36d80e04be721 Mon Sep 17 00:00:00 2001 From: Maximiliano Sandoval R Date: Wed, 15 Nov 2023 22:23:46 +0100 Subject: [PATCH] Add keyring-util Fixes: https://github.com/bilelmoussaoui/oo7/issues/48 --- .gitignore | 1 + keyring-util/Cargo.toml | 11 ++ keyring-util/src/main.rs | 257 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 269 insertions(+) create mode 100644 keyring-util/Cargo.toml create mode 100644 keyring-util/src/main.rs diff --git a/.gitignore b/.gitignore index 96ef6c0b9..3e0525451 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target Cargo.lock +keyring-util/target diff --git a/keyring-util/Cargo.toml b/keyring-util/Cargo.toml new file mode 100644 index 000000000..741b2d3c1 --- /dev/null +++ b/keyring-util/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "keyring-util" +version = "0.1.0" +edition = "2021" + +[dependencies] +async-std = { version = "1.12.0", features = [ "attributes" ] } +chrono = "0.4.31" +clap = { version = "4.4.6", features = [ "cargo" ] } +oo7 = { path = "../" } +rpassword = "7.2.0" diff --git a/keyring-util/src/main.rs b/keyring-util/src/main.rs new file mode 100644 index 000000000..4473459ce --- /dev/null +++ b/keyring-util/src/main.rs @@ -0,0 +1,257 @@ +use std::collections::HashMap; +use std::fmt; +use std::io::Write; +use std::process::{ExitCode, Termination}; + +use clap::parser::ValuesRef; +use clap::{arg, value_parser, Command}; +use oo7::Keyring; + +struct Error(String); + +impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", self.0) + } +} + +impl From for Error { + fn from(_err: oo7::Error) -> Error { + // TODO + Error(String::new()) + } +} + +impl Error { + fn new(s: &str) -> Self { + Self(String::from(s)) + } +} + +impl Termination for Error { + fn report(self) -> ExitCode { + ExitCode::FAILURE + } +} + +#[async_std::main] +async fn main() -> Result<(), Error> { + let cmd = Command::new("keyring-util") + .bin_name("keyring-util") + .subcommand_required(true) + .subcommand( + Command::new("store") + .arg( + arg!(label: