FE 0.13.1
Header-only C++ frontend library
Loading...
Searching...
No Matches
fe::sys Namespace Reference

Classes

class  CmdNotFound
 Thrown by sys::require_cmd when a command cannot be located on the system. More...

Functions

std::optional< std::filesystem::path > path_to_lib (const void *addr)
 Path of the executable or dynamic library that contains addr.
std::string exec (std::string cmd)
 Executes command cmd.
std::string find_cmd (std::string cmd)
 Locates cmd via sys::which; the resulting path may not exist.
std::string require_cmd (std::string_view name)
 Locates name on the system or throws CmdNotFound.
int system (std::string cmd)
 Wraps std::system and makes the return value usable.
void require_run (const std::string &cmd)
 Runs cmd via sys::system and throws if it exits with a non-zero status.
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.
std::string escape (const std::filesystem::path &path)
 Returns the path as std::string and escapes all whitespaces with backslash.

Variables

static constexpr auto which
 Name of the command that locates an executable on this platform.

Function Documentation

◆ escape()

std::string fe::sys::escape ( const std::filesystem::path & path)

Returns the path as std::string and escapes all whitespaces with backslash.

References escape().

Referenced by escape().

◆ exec()

std::string fe::sys::exec ( std::string cmd)

Executes command cmd.

Returns
the output as string.

References exec().

Referenced by exec().

◆ find_cmd()

std::string fe::sys::find_cmd ( std::string cmd)

Locates cmd via sys::which; the resulting path may not exist.

References find_cmd().

Referenced by find_cmd().

◆ path_to_lib()

std::optional< std::filesystem::path > fe::sys::path_to_lib ( const void * addr)

Path of the executable or dynamic library that contains addr.

Pass the address of a function of your own to find out where you have been loaded from.

Returns
std::nullopt if an error occurred or the platform is not supported.

References path_to_lib().

Referenced by path_to_lib().

◆ require_cmd()

std::string fe::sys::require_cmd ( std::string_view name)

Locates name on the system or throws CmdNotFound.

References require_cmd().

Referenced by require_cmd().

◆ require_run()

void fe::sys::require_run ( const std::string & cmd)

Runs cmd via sys::system and throws if it exits with a non-zero status.

References require_run().

Referenced by require_run().

◆ run()

int fe::sys::run ( std::string cmd,
std::string args = {} )

Wraps sys::system and puts .exe at the back (Windows) and ./ at the front (otherwise) of cmd.

References run().

Referenced by run().

◆ system()

int fe::sys::system ( std::string cmd)

Wraps std::system and makes the return value usable.

References system().

Referenced by system().

Variable Documentation

◆ which

auto fe::sys::which
staticconstexpr
Initial value:
=
"which"

Name of the command that locates an executable on this platform.

Definition at line 12 of file sys.h.