canonical / multipass

Multipass orchestrates virtual Ubuntu instances
https://multipass.run
GNU General Public License v3.0
7.76k stars 642 forks source link

Improve the cmd utility function implementation #3700

Open georgeliao opened 1 week ago

georgeliao commented 1 week ago

Describe the current situation The current implementation of Utils::run_cmd_for_output, Utils::run_cmd_for_status is stale, meaning that it still interacts the raw QProcess and it did not handle erroneous cases properly. Nowadays, we have the SimpleProcessSpec utility class and process factory to make process, so we can use these to create a general cmd line run utility function. One template of this can be QString get_arp_output() in macos/backend_utils.cpp. The implementation can generalized and migrated into run_cmd_for_output function, the behavior of the function will change because we rethrow in the failed case. That also means the client code of it might have to adapt.

Furthermore, the run_cmd_for_status may no longer be needed, because the new run_cmd_for_output throws. Besides this, maybe function process_throw_on_error and process_log_on_error can be refactored correspondingly and run_cmd_for_output can be used.