33//! SS-URI = "ss://" userinfo "@" hostname ":" port [ "/" ] [ "?" plugin ] [ "#" tag ]
44//! userinfo = websafe-base64-encode-utf8(method ":" password)
55
6+ use std:: process:: ExitCode ;
7+
68use clap:: { Arg , ArgAction , Command , ValueHint } ;
79use qrcode:: { types:: Color , QrCode } ;
810
@@ -72,6 +74,7 @@ fn decode(encoded: &str, need_qrcode: bool) {
7274 }
7375}
7476
77+ #[ cfg( feature = "utility-url-outline" ) ]
7578fn decode_outline ( remote : & str , need_qrcode : bool ) {
7679 // Protect from using http and other non-ssconf links in reqwest call
7780 if !remote. starts_with ( "ssconf" ) {
@@ -92,8 +95,8 @@ fn decode_outline(remote: &str, need_qrcode: bool) {
9295 }
9396}
9497
95- fn main ( ) {
96- let app = Command :: new ( "ssurl" )
98+ fn main ( ) -> ExitCode {
99+ let mut app = Command :: new ( "ssurl" )
97100 . version ( VERSION )
98101 . about ( "Encode and decode ShadowSocks URL" )
99102 . arg (
@@ -116,31 +119,44 @@ fn main() {
116119 . help ( "Decode the server configuration from the provided ShadowSocks URL" ) ,
117120 )
118121 . arg (
122+ Arg :: new ( "QRCODE" )
123+ . short ( 'c' )
124+ . long ( "qrcode" )
125+ . action ( ArgAction :: SetTrue )
126+ . help ( "Generate the QRCode with the provided configuration" ) ,
127+ ) ;
128+
129+ if cfg ! ( feature = "utility-url-outline" ) {
130+ app = app. arg (
119131 Arg :: new ( "OUTLINE_CONFIG_URL" )
120132 . short ( 'o' )
121133 . long ( "outline" )
122134 . value_hint ( ValueHint :: Url )
123135 . required_unless_present_any ( [ "ENCODE_CONFIG_PATH" , "DECODE_CONFIG_PATH" ] )
124136 . help ( "Fetch and decode config from ssconf URL used by Outline" ) ,
125- )
126- . arg (
127- Arg :: new ( "QRCODE" )
128- . short ( 'c' )
129- . long ( "qrcode" )
130- . action ( ArgAction :: SetTrue )
131- . help ( "Generate the QRCode with the provided configuration" ) ,
132137 ) ;
138+ }
139+
133140 let matches = app. get_matches ( ) ;
134141
135142 let need_qrcode = matches. get_flag ( "QRCODE" ) ;
136143
137144 if let Some ( file) = matches. get_one :: < String > ( "ENCODE_CONFIG_PATH" ) {
138145 encode ( file, need_qrcode) ;
139- } else if let Some ( encoded) = matches. get_one :: < String > ( "DECODE_CONFIG_PATH" ) {
146+ return ExitCode :: SUCCESS ;
147+ }
148+
149+ if let Some ( encoded) = matches. get_one :: < String > ( "DECODE_CONFIG_PATH" ) {
140150 decode ( encoded, need_qrcode) ;
141- } else if let Some ( remote) = matches. get_one :: < String > ( "OUTLINE_CONFIG_URL" ) {
151+ return ExitCode :: SUCCESS ;
152+ }
153+
154+ #[ cfg( feature = "utility-url-outline" ) ]
155+ if let Some ( remote) = matches. get_one :: < String > ( "OUTLINE_CONFIG_URL" ) {
142156 decode_outline ( remote, need_qrcode) ;
143- } else {
144- println ! ( "Use -h for more detail" ) ;
157+ return ExitCode :: SUCCESS ;
145158 }
159+
160+ println ! ( "Use -h for more detail" ) ;
161+ return ExitCode :: FAILURE ;
146162}
0 commit comments