FE
0.13.1
Header-only C++ frontend library
Toggle main menu visibility
Loading...
Searching...
No Matches
sys.h
Go to the documentation of this file.
1
#pragma once
2
3
#include <filesystem>
4
#include <optional>
5
#include <stdexcept>
6
#include <string>
7
#include <string_view>
8
9
namespace
fe::sys
{
10
11
/// Name of the command that locates an executable on this platform.
12
static
constexpr
auto
which
=
13
#ifdef _WIN32
14
"where"
;
15
#else
16
"which"
;
17
#endif
18
19
/// Path of the executable or dynamic library that contains @p addr.
20
/// Pass the address of a function of your own to find out where *you* have been loaded from.
21
/// @returns `std::nullopt` if an error occurred or the platform is not supported.
22
std::optional<std::filesystem::path>
path_to_lib
(
const
void
* addr);
23
24
/// Executes command @p cmd.
25
/// @returns the output as string.
26
std::string
exec
(std::string cmd);
27
28
/// Locates @p cmd via sys::which; the resulting path may not exist.
29
std::string
find_cmd
(std::string cmd);
30
31
/// Thrown by sys::require_cmd when a command cannot be located on the system.
32
class
CmdNotFound
:
public
std::logic_error {
33
public
:
34
CmdNotFound
(
const
std::string& s)
35
:
std
::logic_error(s) {}
36
};
37
38
/// Locates @p name on the system or throws CmdNotFound.
39
std::string
require_cmd
(std::string_view name);
40
41
/// Wraps `std::system` and makes the return value usable.
42
int
system
(std::string cmd);
43
44
/// Runs @p cmd via sys::system and throws if it exits with a non-zero status.
45
void
require_run
(
const
std::string& cmd);
46
47
/// Wraps sys::system and puts `.exe` at the back (Windows) and `./` at the front (otherwise) of @p cmd.
48
int
run
(std::string cmd, std::string args = {});
49
50
/// Returns the @p path as `std::string` and escapes all whitespaces with backslash.
51
std::string
escape
(
const
std::filesystem::path& path);
52
53
}
// namespace fe::sys
fe::sys::CmdNotFound::CmdNotFound
CmdNotFound(const std::string &s)
Definition
sys.h:34
fe::sys
Definition
sys.h:9
fe::sys::run
int run(std::string cmd, std::string args={})
Wraps sys::system and puts .exe at the back (Windows) and ./ at the front (otherwise) of cmd.
fe::sys::find_cmd
std::string find_cmd(std::string cmd)
Locates cmd via sys::which; the resulting path may not exist.
fe::sys::escape
std::string escape(const std::filesystem::path &path)
Returns the path as std::string and escapes all whitespaces with backslash.
fe::sys::system
int system(std::string cmd)
Wraps std::system and makes the return value usable.
fe::sys::path_to_lib
std::optional< std::filesystem::path > path_to_lib(const void *addr)
Path of the executable or dynamic library that contains addr.
fe::sys::require_run
void require_run(const std::string &cmd)
Runs cmd via sys::system and throws if it exits with a non-zero status.
fe::sys::require_cmd
std::string require_cmd(std::string_view name)
Locates name on the system or throws CmdNotFound.
fe::sys::which
static constexpr auto which
Name of the command that locates an executable on this platform.
Definition
sys.h:12
fe::sys::exec
std::string exec(std::string cmd)
Executes command cmd.
std
Definition
span.h:129
fe
sys.h
Generated by
1.18.0