@@ -2,26 +2,26 @@ use std::path::Path;
22
33use seahorse:: { ActionError , ActionResult , Context } ;
44
5- use crate :: config:: get_config_path;
5+ use crate :: config:: { get_config_path, get_db_path } ;
66use crate :: error:: invalid;
7- use crate :: storage:: json :: JSONStore ;
8- use crate :: storage:: { Store , StoreValue } ;
7+ use crate :: storage:: sqlite :: SQLiteStore ;
8+ use crate :: storage:: { self , Store , StoreValue } ;
99
1010pub fn init_action ( _c : & Context ) -> ActionResult {
11- let config_path = get_config_path ( ) ;
11+ let config_path = get_db_path ( ) ;
1212 let path = Path :: new ( & config_path) ;
1313
1414 if path. exists ( ) {
1515 println ! ( "config file already exists" ) ;
1616 }
1717
18- JSONStore :: with_force_create ( true ) ;
18+ SQLiteStore :: from_path ( path ) ;
1919
2020 Ok ( ( ) )
2121}
2222
2323pub fn list_action ( c : & Context ) -> ActionResult {
24- let store = JSONStore :: with_force_create ( c . bool_flag ( "force-create" ) ) ;
24+ let store = storage :: load_storage ( ) ;
2525
2626 for ( key, value) in store. all ( ) . iter ( ) {
2727 println ! ( "{}\t {}" , key, value) ;
@@ -31,7 +31,7 @@ pub fn list_action(c: &Context) -> ActionResult {
3131}
3232
3333pub fn clear_action ( _c : & Context ) -> ActionResult {
34- let mut store = JSONStore :: new ( ) ;
34+ let mut store = storage :: load_storage ( ) ;
3535
3636 store. clear ( ) ;
3737
@@ -51,7 +51,7 @@ pub fn get_action(c: &Context) -> ActionResult {
5151 return Err ( invalid ( "key" ) ) ;
5252 } ;
5353
54- let store = JSONStore :: new ( ) ;
54+ let store = storage :: load_storage ( ) ;
5555
5656 let value = store. get ( key) ;
5757
@@ -86,12 +86,12 @@ pub fn set_action(c: &Context) -> ActionResult {
8686 return Err ( invalid ( "value" ) ) ;
8787 } ;
8888
89- let mut store = JSONStore :: new ( ) ;
89+ let mut store = storage :: load_storage ( ) ;
9090
9191 let value = StoreValue :: Value ( value_str. to_owned ( ) ) ;
9292 store. set ( key, value. clone ( ) ) ;
9393
94- println ! ( "{} \t {} " , key, value) ;
94+ println ! ( "'{}' -> '{}' " , key, value) ;
9595
9696 Ok ( ( ) )
9797}
@@ -101,7 +101,7 @@ pub fn remove_action(c: &Context) -> ActionResult {
101101 return Err ( invalid ( "key" ) ) ;
102102 } ;
103103
104- let mut store = JSONStore :: new ( ) ;
104+ let mut store = storage :: load_storage ( ) ;
105105
106106 match store. remove ( key) {
107107 Some ( value) => println ! ( "{}\t {}" , key, value) ,
0 commit comments