BuildCache
sys_utils.hpp
1 //--------------------------------------------------------------------------------------------------
2 // Copyright (c) 2018 Marcus Geelnard
3 //
4 // This software is provided 'as-is', without any express or implied warranty. In no event will the
5 // authors be held liable for any damages arising from the use of this software.
6 //
7 // Permission is granted to anyone to use this software for any purpose, including commercial
8 // applications, and to alter it and redistribute it freely, subject to the following restrictions:
9 //
10 // 1. The origin of this software must not be misrepresented; you must not claim that you wrote
11 // the original software. If you use this software in a product, an acknowledgment in the
12 // product documentation would be appreciated but is not required.
13 //
14 // 2. Altered source versions must be plainly marked as such, and must not be misrepresented as
15 // being the original software.
16 //
17 // 3. This notice may not be removed or altered from any source distribution.
18 //--------------------------------------------------------------------------------------------------
19 
20 #ifndef BUILDCACHE_SYS_UTILS_HPP_
21 #define BUILDCACHE_SYS_UTILS_HPP_
22 
23 #include <base/string_list.hpp>
24 
25 #include <string>
26 
27 namespace bcache {
28 namespace sys {
30 struct run_result_t {
31  std::string std_out;
32  std::string std_err;
33  int return_code = 1;
34 };
35 
42 run_result_t run(const string_list_t& args,
43  const bool quiet = true,
44  const std::string& work_dir = std::string());
45 
57  const bool quiet = true,
58  const std::string& work_dir = std::string());
59 
62 void open_in_default_editor(const std::string& path);
63 
72 void print_raw_stdout(const std::string& str);
73 
82 void print_raw_stderr(const std::string& str);
83 
90 std::string get_local_temp_folder();
91 } // namespace sys
92 } // namespace bcache
93 
94 #endif // BUILDCACHE_SYS_UTILS_HPP_
bcache::sys::run_result_t::std_err
std::string std_err
The contents of stderr.
Definition: sys_utils.hpp:32
bcache::sys::run_result_t
Run results from an external command.
Definition: sys_utils.hpp:30
bcache
The top level namespace.
Definition: compressor.cpp:34
bcache::sys::run
run_result_t run(const string_list_t &args, const bool quiet, const std::string &work_dir)
Run the given command.
Definition: sys_utils.cpp:164
bcache::string_list_t
A convenient vector of strings container with support functions for program argument handling.
Definition: string_list.hpp:30
bcache::sys::print_raw_stderr
void print_raw_stderr(const std::string &str)
Print a string to stderr.
Definition: sys_utils.cpp:565
bcache::sys::open_in_default_editor
void open_in_default_editor(const std::string &path)
Open a file in the user default editor.
Definition: sys_utils.cpp:477
bcache::sys::run_result_t::return_code
int return_code
The program return code (zero for success).
Definition: sys_utils.hpp:33
bcache::sys::get_local_temp_folder
std::string get_local_temp_folder()
Get the temporary folder for this BuildCache instance.
Definition: sys_utils.cpp:579
bcache::sys::run_with_prefix
run_result_t run_with_prefix(const string_list_t &args, const bool quiet, const std::string &work_dir)
Run the given command with an optional prefix.
Definition: sys_utils.cpp:454
bcache::sys::print_raw_stdout
void print_raw_stdout(const std::string &str)
Print a string to stdout.
Definition: sys_utils.cpp:551
bcache::sys::run_result_t::std_out
std::string std_out
The contents of stdout.
Definition: sys_utils.hpp:31