Skip to content

Commit

Permalink
commands: add_person_list, rename_person_list
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedilger committed Nov 27, 2023
1 parent 34d0efd commit b236e5d
Showing 1 changed file with 54 additions and 4 deletions.
58 changes: 54 additions & 4 deletions gossip-bin/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl Command {
}
}

const COMMANDS: [Command; 24] = [
const COMMANDS: [Command; 26] = [
Command {
cmd: "oneshot",
usage_params: "depends",
Expand All @@ -39,6 +39,11 @@ const COMMANDS: [Command; 24] = [
usage_params: "<hexOrBech32String> <relayurl>",
desc: "add the relay as a read and write relay for the person",
},
Command {
cmd: "add_person_list",
usage_params: "<listname>",
desc: "add a new person list with the given name",
},
Command {
cmd: "bech32_decode",
usage_params: "<bech32string>",
Expand Down Expand Up @@ -129,6 +134,11 @@ const COMMANDS: [Command; 24] = [
usage_params: "",
desc: "Rebuild all event-related indices",
},
Command {
cmd: "rename_person_list",
usage_params: "<number> <newname>",
desc: "Rename a person list",
},
Command {
cmd: "reprocess_recent",
usage_params: "",
Expand Down Expand Up @@ -170,6 +180,7 @@ pub fn handle_command(mut args: env::Args, runtime: &Runtime) -> Result<bool, Er
match command.cmd {
"oneshot" => oneshot(command, args)?,
"add_person_relay" => add_person_relay(command, args)?,
"add_person_list" => add_person_list(command, args)?,
"bech32_decode" => bech32_decode(command, args)?,
"bech32_encode_event_addr" => bech32_encode_event_addr(command, args)?,
"decrypt" => decrypt(command, args)?,
Expand All @@ -191,6 +202,7 @@ pub fn handle_command(mut args: env::Args, runtime: &Runtime) -> Result<bool, Er
"print_relay" => print_relay(command, args)?,
"print_relays" => print_relays(command)?,
"rebuild_indices" => rebuild_indices(command)?,
"rename_person_list" => rename_person_list(command, args)?,
"reprocess_recent" => reprocess_recent(command, runtime)?,
"ungiftwrap" => ungiftwrap(command, args)?,
"verify" => verify(command, args)?,
Expand Down Expand Up @@ -241,6 +253,16 @@ pub fn add_person_relay(cmd: Command, mut args: env::Args) -> Result<(), Error>
Ok(())
}

pub fn add_person_list(cmd: Command, mut args: env::Args) -> Result<(), Error> {
let listname = match args.next() {
Some(s) => s,
None => return cmd.usage("Missing listname parameter".to_string()),
};

let _list = PersonList::allocate(&*listname, None)?;
Ok(())
}

pub fn bech32_decode(cmd: Command, mut args: env::Args) -> Result<(), Error> {
let mut param = match args.next() {
Some(s) => s,
Expand Down Expand Up @@ -465,12 +487,20 @@ pub fn print_person_lists(_cmd: Command) -> Result<(), Error> {
let lists = PersonList::all_lists();
for (list, name) in lists.iter() {
println!("LIST {}: {}", u8::from(*list), name);
let pubkeys = GLOBALS.storage.get_people_in_list(*list, None)?;
let pubkeys = GLOBALS.storage.get_people_in_list(*list, Some(true))?;
for pk in &pubkeys {
if let Some(person) = GLOBALS.storage.read_person(pk)? {
println!("{} {}", pk.as_hex_string(), person.best_name());
println!("public: {} {}", pk.as_hex_string(), person.best_name());
} else {
println!("{}", pk.as_hex_string());
println!("public: {}", pk.as_hex_string());
}
}
let pubkeys = GLOBALS.storage.get_people_in_list(*list, Some(false))?;
for pk in &pubkeys {
if let Some(person) = GLOBALS.storage.read_person(pk)? {
println!("private: {} {}", pk.as_hex_string(), person.best_name());
} else {
println!("private: {}", pk.as_hex_string());
}
}
println!("");
Expand Down Expand Up @@ -658,6 +688,26 @@ pub fn rebuild_indices(cmd: Command) -> Result<(), Error> {
Ok(())
}

pub fn rename_person_list(cmd: Command, mut args: env::Args) -> Result<(), Error> {
let number: u8 = match args.next() {
Some(number) => number.parse::<u8>()?,
None => return cmd.usage("Missing number parameter".to_string()),
};

let newname = match args.next() {
Some(name) => name,
None => return cmd.usage("Missing newname parameter".to_string()),
};

if let Some(list) = PersonList::from_number(number) {
list.rename(&*newname, None)?;
} else {
println!("No list with number={}", number);
}

Ok(())
}

pub fn login(_cmd: Command) -> Result<(), Error> {
let mut password = rpassword::prompt_password("Password: ").unwrap();
let epk = match GLOBALS.storage.read_encrypted_private_key()? {
Expand Down

0 comments on commit b236e5d

Please sign in to comment.