support creating a namespace by letting the user type in a namespace. In the future while I replace dialouger I'll have a typeahead-style selection widget to let me unify these two functions

This commit is contained in:
Tom Alexander 2019-10-07 15:47:37 -04:00
parent a3c6655db1
commit ce003c18fb
No known key found for this signature in database
GPG Key ID: 76046DA92D2604F7

View File

@ -181,11 +181,28 @@ fn change_namespace(db_conn: &mut db::DbHandle, master_key: [u8; 32]) -> String
namespaces[selection].name.to_owned() namespaces[selection].name.to_owned()
} }
fn create_namespace(db_conn: &mut db::DbHandle, master_key: [u8; 32]) -> String {
let namespace: String = Input::with_theme(&ColorfulTheme::default())
.with_prompt("Namespace")
.default("main".to_owned())
.interact()
.unwrap();
namespace
}
fn shell(db_conn: &mut db::DbHandle, master_key: [u8; 32], _namespace: &str) { fn shell(db_conn: &mut db::DbHandle, master_key: [u8; 32], _namespace: &str) {
let mut namespace: String = _namespace.to_owned(); let mut namespace: String = _namespace.to_owned();
loop { loop {
let selections = &["get", "list", "set", "generate", "change namespace", "exit"]; let selections = &[
"get",
"list",
"set",
"generate",
"change namespace",
"create namespace",
"exit",
];
let main_menu_prompt = format!("Main Menu ({})", namespace); let main_menu_prompt = format!("Main Menu ({})", namespace);
let selection = Select::with_theme(&ColorfulTheme::default()) let selection = Select::with_theme(&ColorfulTheme::default())
@ -202,6 +219,9 @@ fn shell(db_conn: &mut db::DbHandle, master_key: [u8; 32], _namespace: &str) {
"change namespace" => { "change namespace" => {
namespace = change_namespace(db_conn, master_key); namespace = change_namespace(db_conn, master_key);
} }
"create namespace" => {
namespace = create_namespace(db_conn, master_key);
}
"exit" => break, "exit" => break,
_ => panic!("Unrecognized command"), _ => panic!("Unrecognized command"),
}; };