Skip to content

Commit fc7d88c

Browse files
liudongmiaozonyitoo
authored andcommitted
add command argument --plugin-mode, should close #1495
1 parent ec75237 commit fc7d88c

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

src/service/local.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,14 @@ pub fn define_command_line_options(mut app: Command) -> Command {
176176
.requires("SERVER_ADDR")
177177
.help("SIP003 (https://shadowsocks.org/guide/sip003.html) plugin"),
178178
)
179+
.arg(
180+
Arg::new("PLUGIN_MODE")
181+
.long("plugin-mode")
182+
.num_args(1)
183+
.action(ArgAction::Set)
184+
.requires("PLUGIN")
185+
.help("SIP003/SIP003u plugin mode, must be one of `tcp_only` (default), `udp_only` and `tcp_and_udp`"),
186+
)
179187
.arg(
180188
Arg::new("PLUGIN_OPT")
181189
.long("plugin-opts")
@@ -623,7 +631,9 @@ pub fn create(matches: &ArgMatches) -> Result<(Runtime, impl Future<Output = Exi
623631
plugin: p,
624632
plugin_opts: matches.get_one::<String>("PLUGIN_OPT").cloned(),
625633
plugin_args: Vec::new(),
626-
plugin_mode: Mode::TcpOnly,
634+
plugin_mode: matches.get_one::<String>("PLUGIN_MODE")
635+
.map(|x| x.parse::<Mode>().expect("plugin-mode must be one of `tcp_only` (default), `udp_only` and `tcp_and_udp`"))
636+
.unwrap_or(Mode::TcpOnly),
627637
};
628638

629639
sc.set_plugin(plugin);

src/service/manager.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ pub fn define_command_line_options(mut app: Command) -> Command {
9595
.value_hint(ValueHint::CommandName)
9696
.help("Default SIP003 (https://shadowsocks.org/guide/sip003.html) plugin"),
9797
)
98+
.arg(
99+
Arg::new("PLUGIN_MODE")
100+
.long("plugin-mode")
101+
.num_args(1)
102+
.action(ArgAction::Set)
103+
.requires("PLUGIN")
104+
.help("SIP003/SIP003u plugin mode, must be one of `tcp_only` (default), `udp_only` and `tcp_and_udp`"),
105+
)
98106
.arg(
99107
Arg::new("PLUGIN_OPT")
100108
.long("plugin-opts")
@@ -377,7 +385,9 @@ pub fn create(matches: &ArgMatches) -> Result<(Runtime, impl Future<Output = Exi
377385
plugin: p,
378386
plugin_opts: matches.get_one::<String>("PLUGIN_OPT").cloned(),
379387
plugin_args: Vec::new(),
380-
plugin_mode: Mode::TcpOnly,
388+
plugin_mode: matches.get_one::<String>("PLUGIN_MODE")
389+
.map(|x| x.parse::<Mode>().expect("plugin-mode must be one of `tcp_only` (default), `udp_only` and `tcp_and_udp`"))
390+
.unwrap_or(Mode::TcpOnly),
381391
});
382392
}
383393

src/service/server.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,14 @@ pub fn define_command_line_options(mut app: Command) -> Command {
123123
.requires("SERVER_ADDR")
124124
.help("SIP003 (https://shadowsocks.org/guide/sip003.html) plugin"),
125125
)
126+
.arg(
127+
Arg::new("PLUGIN_MODE")
128+
.long("plugin-mode")
129+
.num_args(1)
130+
.action(ArgAction::Set)
131+
.requires("PLUGIN")
132+
.help("SIP003/SIP003u plugin mode, must be one of `tcp_only` (default), `udp_only` and `tcp_and_udp`"),
133+
)
126134
.arg(
127135
Arg::new("PLUGIN_OPT")
128136
.long("plugin-opts")
@@ -358,7 +366,9 @@ pub fn create(matches: &ArgMatches) -> Result<(Runtime, impl Future<Output = Exi
358366
plugin: p,
359367
plugin_opts: matches.get_one::<String>("PLUGIN_OPT").cloned(),
360368
plugin_args: Vec::new(),
361-
plugin_mode: Mode::TcpOnly,
369+
plugin_mode: matches.get_one::<String>("PLUGIN_MODE")
370+
.map(|x| x.parse::<Mode>().expect("plugin-mode must be one of `tcp_only` (default), `udp_only` and `tcp_and_udp`"))
371+
.unwrap_or(Mode::TcpOnly),
362372
};
363373

364374
sc.set_plugin(plugin);

0 commit comments

Comments
 (0)