1+ use crate :: services:: config:: Error ;
12use clap:: ArgMatches ;
2- use colored:: Colorize ;
33
4- pub ( crate ) fn parse < ' a > ( args : & ' a ArgMatches < ' _ > ) -> Command < ' a > {
4+ pub ( crate ) fn parse < ' a > ( args : & ' a ArgMatches < ' _ > ) -> Result < Command < ' a > , Error > {
55 if args. is_present ( "issue" ) {
66 issue (
77 & args
@@ -27,72 +27,68 @@ pub(crate) fn parse<'a>(args: &'a ArgMatches<'_>) -> Command<'a> {
2727 . expect ( "Error parsing request" ) ,
2828 )
2929 } else if args. is_present ( "create-proof" ) {
30- return create_proof (
30+ create_proof (
3131 & args
3232 . subcommand_matches ( "create-proof" )
3333 . expect ( "Error parsing request" ) ,
34- ) ;
34+ )
3535 } else if args. is_present ( "verify-proof" ) {
36- return verify_proof (
36+ verify_proof (
3737 & args
3838 . subcommand_matches ( "verify-proof" )
3939 . expect ( "Error parsing request" ) ,
40- ) ;
40+ )
4141 } else {
42- println ! (
43- "{}" ,
44- format!( "invalid subcommand. see 'trinsic vc -h' for details" ) . red( )
45- ) ;
46- panic ! ( ) ;
42+ Err ( Error :: MissingArguments )
4743 }
4844}
4945
50- fn issue < ' a > ( args : & ' a ArgMatches < ' _ > ) -> Command < ' a > {
51- Command :: Issue ( IssueArgs {
46+ fn issue < ' a > ( args : & ' a ArgMatches < ' _ > ) -> Result < Command < ' a > , Error > {
47+ Ok ( Command :: Issue ( IssueArgs {
5248 document : args. value_of ( "document" ) ,
5349 out : args. value_of ( "out" ) ,
54- } )
50+ } ) )
5551}
5652
57- fn issue_from_template < ' a > ( args : & ' a ArgMatches < ' _ > ) -> Command < ' a > {
58- Command :: IssueFromTemplate ( IssueFromTemplateArgs {
53+ fn issue_from_template < ' a > ( args : & ' a ArgMatches < ' _ > ) -> Result < Command < ' a > , Error > {
54+ Ok ( Command :: IssueFromTemplate ( IssueFromTemplateArgs {
5955 template_id : args
6056 . value_of ( "template-id" )
6157 . map_or ( String :: default ( ) , |x| x. to_string ( ) ) ,
6258 values_json : args. value_of ( "values-data" ) . map ( |x| x. to_string ( ) ) ,
6359 values_file : args. value_of ( "values-file" ) . map ( |x| x. to_string ( ) ) ,
64- } )
60+ } ) )
6561}
6662
67- fn get_status < ' a > ( args : & ' a ArgMatches < ' _ > ) -> Command < ' a > {
68- Command :: GetStatus ( GetStatusArgs {
63+ fn get_status < ' a > ( args : & ' a ArgMatches < ' _ > ) -> Result < Command < ' a > , Error > {
64+ Ok ( Command :: GetStatus ( GetStatusArgs {
6965 credential_status_id : args
7066 . value_of ( "credential-status-id" )
7167 . map_or ( String :: default ( ) , |x| x. to_string ( ) ) ,
72- } )
68+ } ) )
7369}
7470
75- fn update_status < ' a > ( args : & ' a ArgMatches < ' _ > ) -> Command < ' a > {
76- Command :: UpdateStatus ( UpdateStatusArgs {
71+ fn update_status < ' a > ( args : & ' a ArgMatches < ' _ > ) -> Result < Command < ' a > , Error > {
72+ Ok ( Command :: UpdateStatus ( UpdateStatusArgs {
7773 credential_status_id : args
7874 . value_of ( "credential-status-id" )
7975 . map_or ( String :: default ( ) , |x| x. to_string ( ) ) ,
8076 revoked : args. is_present ( "revoked" ) ,
81- } )
77+ } ) )
8278}
8379
84- fn create_proof < ' a > ( args : & ' a ArgMatches < ' _ > ) -> Command < ' a > {
85- Command :: CreateProof ( CreateProofArgs {
80+ fn create_proof < ' a > ( args : & ' a ArgMatches < ' _ > ) -> Result < Command < ' a > , Error > {
81+ Ok ( Command :: CreateProof ( CreateProofArgs {
8682 reveal_document : args. value_of ( "reveal-document" ) ,
8783 document_id : args. value_of ( "document-id" ) ,
8884 out : args. value_of ( "out" ) ,
89- } )
85+ } ) )
9086}
9187
92- fn verify_proof < ' a > ( args : & ' a ArgMatches < ' _ > ) -> Command < ' a > {
93- Command :: VerifyProof ( VerifyProofArgs {
88+ fn verify_proof < ' a > ( args : & ' a ArgMatches < ' _ > ) -> Result < Command < ' a > , Error > {
89+ Ok ( Command :: VerifyProof ( VerifyProofArgs {
9490 proof_document : args. value_of ( "proof-document" ) ,
95- } )
91+ } ) )
9692}
9793
9894#[ derive( Debug , PartialEq ) ]
0 commit comments