@@ -2,14 +2,11 @@ use crate::Context;
22use atomic_lib:: { errors:: AtomicResult , Storelike } ;
33
44/// Apply a Commit using the Set method - create or update a value in a resource
5- pub fn set ( context : & Context ) -> AtomicResult < ( ) > {
6- let subject = argument_to_url ( context, "subject" ) ?;
7- let property = argument_to_string ( context, "property" ) ?;
8- let value = argument_to_string ( context, "value" ) ?;
5+ pub fn set ( context : & Context , subject : & str , property : & str , value : & str ) -> AtomicResult < ( ) > {
96 // If the resource is not found, create it
10- let mut resource = match context. store . get_resource ( & subject) {
7+ let mut resource = match context. store . get_resource ( subject) {
118 Ok ( r) => r,
12- Err ( _) => atomic_lib:: Resource :: new ( subject) ,
9+ Err ( _) => atomic_lib:: Resource :: new ( subject. into ( ) ) ,
1310 } ;
1411 resource. set_shortname ( & property, & value, & context. store ) ?;
1512 resource. save ( & context. store ) ?;
@@ -18,13 +15,11 @@ pub fn set(context: &Context) -> AtomicResult<()> {
1815
1916/// Apply a Commit using the Set method, where the value is edited in the user's text editor.
2017#[ cfg( feature = "native" ) ]
21- pub fn edit ( context : & Context ) -> AtomicResult < ( ) > {
22- let subject = argument_to_url ( context, "subject" ) ?;
23- let prop = argument_to_string ( context, "property" ) ?;
18+ pub fn edit ( context : & Context , subject : & str , prop : & str ) -> AtomicResult < ( ) > {
2419 // If the resource is not found, create it
2520 let mut resource = match context. store . get_resource ( & subject) {
2621 Ok ( r) => r,
27- Err ( _) => atomic_lib:: Resource :: new ( subject) ,
22+ Err ( _) => atomic_lib:: Resource :: new ( subject. into ( ) ) ,
2823 } ;
2924 // If the prop is not found, create it
3025 let current_val = match resource. get_shortname ( & prop, & context. store ) {
@@ -40,45 +35,16 @@ pub fn edit(context: &Context) -> AtomicResult<()> {
4035}
4136
4237/// Apply a Commit using the Remove method - removes a property from a resource
43- pub fn remove ( context : & Context ) -> AtomicResult < ( ) > {
44- let subject = argument_to_url ( context, "subject" ) ?;
45- let prop = argument_to_string ( context, "property" ) ?;
46- let mut resource = context. store . get_resource ( & subject) ?;
38+ pub fn remove ( context : & Context , subject : & str , prop : & str ) -> AtomicResult < ( ) > {
39+ let mut resource = context. store . get_resource ( subject) ?;
4740 resource. remove_propval_shortname ( & prop, & context. store ) ?;
4841 resource. save ( & context. store ) ?;
4942 Ok ( ( ) )
5043}
5144
5245/// Apply a Commit using the destroy method - removes a resource
53- pub fn destroy ( context : & Context ) -> AtomicResult < ( ) > {
54- let subject = argument_to_url ( context, "subject" ) ?;
55- let mut resource = context. store . get_resource ( & subject) ?;
46+ pub fn destroy ( context : & Context , subject : & str ) -> AtomicResult < ( ) > {
47+ let mut resource = context. store . get_resource ( subject) ?;
5648 resource. destroy ( & context. store ) ?;
5749 Ok ( ( ) )
5850}
59-
60- /// Parses a single argument as string
61- fn argument_to_string ( context : & Context , argument : & str ) -> AtomicResult < String > {
62- let command_name = context. matches . subcommand_name ( ) . unwrap ( ) ;
63- let subcommand_matches = context. matches . subcommand_matches ( command_name) . unwrap ( ) ;
64- let user_arg = subcommand_matches
65- . get_one :: < String > ( argument)
66- . ok_or ( format ! ( "No argument value for {} found" , argument) ) ?;
67- Ok ( user_arg. to_string ( ) )
68- }
69-
70- /// Parses a single argument (URL or Bookmark), should return a valid URL
71- fn argument_to_url ( context : & Context , argument : & str ) -> AtomicResult < String > {
72- let command_name = context. matches . subcommand_name ( ) . unwrap ( ) ;
73- let subcommand_matches = context. matches . subcommand_matches ( command_name) . unwrap ( ) ;
74- let user_arg = subcommand_matches
75- . get_one :: < String > ( argument)
76- . ok_or ( format ! ( "No argument value for {} found" , argument) ) ?;
77- let id_url: String = context
78- . mapping
79- . lock ( )
80- . unwrap ( )
81- . try_mapping_or_url ( & String :: from ( user_arg) )
82- . ok_or ( & * format ! ( "No url found for {}" , user_arg) ) ?;
83- Ok ( id_url)
84- }
0 commit comments