Skip to content

Commit

Permalink
Implements 'key ls' command
Browse files Browse the repository at this point in the history
  • Loading branch information
ultimaweapon committed May 11, 2024
1 parent 7df974a commit 2461e74
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
31 changes: 26 additions & 5 deletions src/cmd/key.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
use crate::key::KeyMgr;
use clap::{ArgMatches, Command};
use std::process::ExitCode;
use std::sync::Arc;

/// Command to manage file encryption keys.
pub struct Key {}
pub struct Key {
keymgr: Arc<KeyMgr>,
}

impl Key {
pub const NAME: &'static str = "key";

pub fn new() -> Self {
Self {}
pub fn new(keymgr: Arc<KeyMgr>) -> Self {
Self { keymgr }
}

fn ls(&self, _: &ArgMatches) -> ExitCode {
let mut t = tabled::builder::Builder::new();

t.push_record(["ID"]);

for k in self.keymgr.keys() {
t.push_record([k.id().to_string()]);
}

println!("{}", t.build());

ExitCode::SUCCESS
}
}

Expand All @@ -24,7 +42,10 @@ impl super::Command for Key {
.subcommand(Command::new("ls").about("List all available keys"))
}

fn exec(&self, _: &ArgMatches) -> ExitCode {
todo!()
fn exec(&self, args: &ArgMatches) -> ExitCode {
match args.subcommand().unwrap() {
("ls", args) => self.ls(args),
_ => unreachable!(),
}
}
}
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn main() -> ExitCode {
let mut args = clap::Command::new("warp");
let commands: Vec<Box<dyn Command>> = vec![
Box::new(self::cmd::Init::new(config.clone(), keymgr.clone())),
Box::new(self::cmd::Key::new()),
Box::new(self::cmd::Key::new(keymgr.clone())),
Box::new(self::cmd::Keystore::new(keymgr.clone())),
];

Expand Down

0 comments on commit 2461e74

Please sign in to comment.