@@ -36,10 +36,11 @@ namespace {
3636 auto verbose = arguments.as_bool (flags::VERBOSE).unwrap_or (false );
3737 auto force_wrapper = arguments.as_bool (cmd::intercept::FLAG_FORCE_WRAPPER).unwrap_or (false );
3838 auto force_preload = arguments.as_bool (cmd::intercept::FLAG_FORCE_PRELOAD).unwrap_or (false );
39+ auto enable_network_proxy = arguments.as_bool (cmd::intercept::FLAG_ENABLE_NETWORK_PROXY).unwrap_or (false );
3940
4041 return rust::merge (program, command, rust::merge (library, wrapper, wrapper_dir))
4142 .map <sys::Process::Builder>(
42- [&environment, &output, &verbose, &force_wrapper, &force_preload](auto tuple) {
43+ [&environment, &output, &verbose, &force_wrapper, &force_preload, &enable_network_proxy ](auto tuple) {
4344 const auto &[program, command, pack] = tuple;
4445 const auto &[library, wrapper, wrapper_dir] = pack;
4546
@@ -57,6 +58,9 @@ namespace {
5758 if (force_preload) {
5859 builder.add_argument (cmd::intercept::FLAG_FORCE_PRELOAD);
5960 }
61+ if (enable_network_proxy) {
62+ builder.add_argument (cmd::intercept::FLAG_ENABLE_NETWORK_PROXY);
63+ }
6064 if (verbose) {
6165 builder.add_argument (flags::VERBOSE);
6266 }
@@ -146,13 +150,14 @@ namespace bear {
146150 rust::Result<flags::Arguments> Application::parse (int argc, const char **argv) const
147151 {
148152 const flags::Parser intercept_parser (" intercept" , cmd::VERSION, {
149- {cmd::intercept::FLAG_OUTPUT, {1 , false , " path of the result file" , {cmd::intercept::DEFAULT_OUTPUT}, std::nullopt }},
150- {cmd::intercept::FLAG_FORCE_PRELOAD, {0 , false , " force to use library preload" , std::nullopt , DEVELOPER_GROUP}},
151- {cmd::intercept::FLAG_FORCE_WRAPPER, {0 , false , " force to use compiler wrappers" , std::nullopt , DEVELOPER_GROUP}},
152- {cmd::intercept::FLAG_LIBRARY, {1 , false , " path to the preload library" , {cmd::library::DEFAULT_PATH}, DEVELOPER_GROUP}},
153- {cmd::intercept::FLAG_WRAPPER, {1 , false , " path to the wrapper executable" , {cmd::wrapper::DEFAULT_PATH}, DEVELOPER_GROUP}},
154- {cmd::intercept::FLAG_WRAPPER_DIR, {1 , false , " path to the wrapper directory" , {cmd::wrapper::DEFAULT_DIR_PATH}, DEVELOPER_GROUP}},
155- {cmd::intercept::FLAG_COMMAND, {-1 , true , " command to execute" , std::nullopt , std::nullopt }}
153+ {cmd::intercept::FLAG_OUTPUT, {1 , false , " path of the result file" , {cmd::intercept::DEFAULT_OUTPUT}, std::nullopt }},
154+ {cmd::intercept::FLAG_FORCE_PRELOAD, {0 , false , " force to use library preload" , std::nullopt , DEVELOPER_GROUP}},
155+ {cmd::intercept::FLAG_FORCE_WRAPPER, {0 , false , " force to use compiler wrappers" , std::nullopt , DEVELOPER_GROUP}},
156+ {cmd::intercept::FLAG_ENABLE_NETWORK_PROXY, {0 , false , " enable http and https proxy" , std::nullopt , DEVELOPER_GROUP}},
157+ {cmd::intercept::FLAG_LIBRARY, {1 , false , " path to the preload library" , {cmd::library::DEFAULT_PATH}, DEVELOPER_GROUP}},
158+ {cmd::intercept::FLAG_WRAPPER, {1 , false , " path to the wrapper executable" , {cmd::wrapper::DEFAULT_PATH}, DEVELOPER_GROUP}},
159+ {cmd::intercept::FLAG_WRAPPER_DIR, {1 , false , " path to the wrapper directory" , {cmd::wrapper::DEFAULT_DIR_PATH}, DEVELOPER_GROUP}},
160+ {cmd::intercept::FLAG_COMMAND, {-1 , true , " command to execute" , std::nullopt , std::nullopt }}
156161 });
157162
158163 const flags::Parser citnames_parser (" citnames" , cmd::VERSION, {
@@ -164,16 +169,17 @@ namespace bear {
164169 });
165170
166171 const flags::Parser parser (" bear" , cmd::VERSION, {intercept_parser, citnames_parser}, {
167- {cmd::citnames::FLAG_OUTPUT, {1 , false , " path of the result file" , {cmd::citnames::DEFAULT_OUTPUT}, std::nullopt }},
168- {cmd::citnames::FLAG_APPEND, {0 , false , " append result to an existing output file" , std::nullopt , ADVANCED_GROUP}},
169- {cmd::citnames::FLAG_CONFIG, {1 , false , " path of the config file" , std::nullopt , ADVANCED_GROUP}},
170- {cmd::intercept::FLAG_FORCE_PRELOAD, {0 , false , " force to use library preload" , std::nullopt , ADVANCED_GROUP}},
171- {cmd::intercept::FLAG_FORCE_WRAPPER, {0 , false , " force to use compiler wrappers" , std::nullopt , ADVANCED_GROUP}},
172- {cmd::bear::FLAG_BEAR, {1 , false , " path to the bear executable" , {cmd::bear::DEFAULT_PATH}, DEVELOPER_GROUP}},
173- {cmd::intercept::FLAG_LIBRARY, {1 , false , " path to the preload library" , {cmd::library::DEFAULT_PATH}, DEVELOPER_GROUP}},
174- {cmd::intercept::FLAG_WRAPPER, {1 , false , " path to the wrapper executable" , {cmd::wrapper::DEFAULT_PATH}, DEVELOPER_GROUP}},
175- {cmd::intercept::FLAG_WRAPPER_DIR, {1 , false , " path to the wrapper directory" , {cmd::wrapper::DEFAULT_DIR_PATH}, DEVELOPER_GROUP}},
176- {cmd::intercept::FLAG_COMMAND, {-1 , true , " command to execute" , std::nullopt , std::nullopt }}
172+ {cmd::citnames::FLAG_OUTPUT, {1 , false , " path of the result file" , {cmd::citnames::DEFAULT_OUTPUT}, std::nullopt }},
173+ {cmd::citnames::FLAG_APPEND, {0 , false , " append result to an existing output file" , std::nullopt , ADVANCED_GROUP}},
174+ {cmd::citnames::FLAG_CONFIG, {1 , false , " path of the config file" , std::nullopt , ADVANCED_GROUP}},
175+ {cmd::intercept::FLAG_FORCE_PRELOAD, {0 , false , " force to use library preload" , std::nullopt , ADVANCED_GROUP}},
176+ {cmd::intercept::FLAG_FORCE_WRAPPER, {0 , false , " force to use compiler wrappers" , std::nullopt , ADVANCED_GROUP}},
177+ {cmd::intercept::FLAG_ENABLE_NETWORK_PROXY, {0 , false , " enable http and https proxy" , std::nullopt , ADVANCED_GROUP}},
178+ {cmd::bear::FLAG_BEAR, {1 , false , " path to the bear executable" , {cmd::bear::DEFAULT_PATH}, DEVELOPER_GROUP}},
179+ {cmd::intercept::FLAG_LIBRARY, {1 , false , " path to the preload library" , {cmd::library::DEFAULT_PATH}, DEVELOPER_GROUP}},
180+ {cmd::intercept::FLAG_WRAPPER, {1 , false , " path to the wrapper executable" , {cmd::wrapper::DEFAULT_PATH}, DEVELOPER_GROUP}},
181+ {cmd::intercept::FLAG_WRAPPER_DIR, {1 , false , " path to the wrapper directory" , {cmd::wrapper::DEFAULT_DIR_PATH}, DEVELOPER_GROUP}},
182+ {cmd::intercept::FLAG_COMMAND, {-1 , true , " command to execute" , std::nullopt , std::nullopt }}
177183 });
178184 return parser.parse_or_exit (argc, const_cast <const char **>(argv));
179185 }
@@ -186,6 +192,12 @@ namespace bear {
186192 return citnames.subcommand (args, envp);
187193 }
188194 if (auto intercept = ic::Intercept (log_config_); intercept.matches (args)) {
195+ // Network proxy is disabled by default unless user explicitly enables it
196+ if (!args.as_bool (cmd::intercept::FLAG_ENABLE_NETWORK_PROXY).unwrap_or (false )) {
197+ for (auto proxyEnv : cmd::intercept::PROXY_ENV_VARS) {
198+ unsetenv (proxyEnv);
199+ }
200+ }
189201 return intercept.subcommand (args, envp);
190202 }
191203 return rust::Err (std::runtime_error (" Invalid subcommand" ));
0 commit comments