Skip to content

Commit

Permalink
add command argument --plugin-mode, should close #1495
Browse files Browse the repository at this point in the history
  • Loading branch information
liudongmiao committed Apr 26, 2024
1 parent ec75237 commit 2528932
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
12 changes: 11 additions & 1 deletion src/service/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,14 @@ pub fn define_command_line_options(mut app: Command) -> Command {
.requires("SERVER_ADDR")
.help("SIP003 (https://shadowsocks.org/guide/sip003.html) plugin"),
)
.arg(
Arg::new("PLUGIN_MODE")
.long("plugin-mode")
.num_args(1)
.action(ArgAction::Set)
.requires("PLUGIN")
.help("SIP003/SIP003u plugin mode, must be one of `tcp_only` (default), `udp_only` and `tcp_and_udp`"),
)
.arg(
Arg::new("PLUGIN_OPT")
.long("plugin-opts")
Expand Down Expand Up @@ -623,7 +631,9 @@ pub fn create(matches: &ArgMatches) -> Result<(Runtime, impl Future<Output = Exi
plugin: p,
plugin_opts: matches.get_one::<String>("PLUGIN_OPT").cloned(),
plugin_args: Vec::new(),
plugin_mode: Mode::TcpOnly,
plugin_mode: matches.get_one::<String>("PLUGIN_MODE")
.map(|x| x.parse::<Mode>().expect("plugin-mode must be one of `tcp_only` (default), `udp_only` and `tcp_and_udp`"))
.unwrap_or(Mode::TcpOnly),
};

sc.set_plugin(plugin);
Expand Down
12 changes: 11 additions & 1 deletion src/service/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ pub fn define_command_line_options(mut app: Command) -> Command {
.value_hint(ValueHint::CommandName)
.help("Default SIP003 (https://shadowsocks.org/guide/sip003.html) plugin"),
)
.arg(
Arg::new("PLUGIN_MODE")
.long("plugin-mode")
.num_args(1)
.action(ArgAction::Set)
.requires("PLUGIN")
.help("SIP003/SIP003u plugin mode, must be one of `tcp_only` (default), `udp_only` and `tcp_and_udp`"),
)
.arg(
Arg::new("PLUGIN_OPT")
.long("plugin-opts")
Expand Down Expand Up @@ -377,7 +385,9 @@ pub fn create(matches: &ArgMatches) -> Result<(Runtime, impl Future<Output = Exi
plugin: p,
plugin_opts: matches.get_one::<String>("PLUGIN_OPT").cloned(),
plugin_args: Vec::new(),
plugin_mode: Mode::TcpOnly,
plugin_mode: matches.get_one::<String>("PLUGIN_MODE")
.map(|x| x.parse::<Mode>().expect("plugin-mode must be one of `tcp_only` (default), `udp_only` and `tcp_and_udp`"))
.unwrap_or(Mode::TcpOnly),
});
}

Expand Down
12 changes: 11 additions & 1 deletion src/service/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ pub fn define_command_line_options(mut app: Command) -> Command {
.requires("SERVER_ADDR")
.help("SIP003 (https://shadowsocks.org/guide/sip003.html) plugin"),
)
.arg(
Arg::new("PLUGIN_MODE")
.long("plugin-mode")
.num_args(1)
.action(ArgAction::Set)
.requires("PLUGIN")
.help("SIP003/SIP003u plugin mode, must be one of `tcp_only` (default), `udp_only` and `tcp_and_udp`"),
)
.arg(
Arg::new("PLUGIN_OPT")
.long("plugin-opts")
Expand Down Expand Up @@ -358,7 +366,9 @@ pub fn create(matches: &ArgMatches) -> Result<(Runtime, impl Future<Output = Exi
plugin: p,
plugin_opts: matches.get_one::<String>("PLUGIN_OPT").cloned(),
plugin_args: Vec::new(),
plugin_mode: Mode::TcpOnly,
plugin_mode: matches.get_one::<String>("PLUGIN_MODE")
.map(|x| x.parse::<Mode>().expect("plugin-mode must be one of `tcp_only` (default), `udp_only` and `tcp_and_udp`"))
.unwrap_or(Mode::TcpOnly),
};

sc.set_plugin(plugin);
Expand Down

0 comments on commit 2528932

Please sign in to comment.