mirror of
https://github.com/CHN-beta/nixos.git
synced 2024-10-23 04:38:44 +08:00
localPackages.biu: add env
This commit is contained in:
parent
fb4a9644fc
commit
1949ea7d78
@ -1,3 +1,3 @@
|
||||
CompileFlags:
|
||||
Add: [ -Wall, -Wextra, -std=c++23 ]
|
||||
Compiler: gcc
|
||||
Compiler: g++
|
@ -22,7 +22,7 @@ find_path(NAMEOF_INCLUDE_DIR nameof.hpp REQUIRED)
|
||||
# find_library(BACKTRACE_LIB backtrace REQUIRED)
|
||||
|
||||
# add_library(biu SHARED src/common.cpp src/logger.cpp src/string.cpp)
|
||||
add_library(biu SHARED src/common.cpp)
|
||||
add_library(biu SHARED src/common.cpp src/env.cpp)
|
||||
target_include_directories(biu PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
||||
|
@ -40,3 +40,10 @@ std::regex operator""_re(const char* str, std::size_t len);
|
||||
inline namespace stream_operators { using namespace magic_enum::iostream_operators; }
|
||||
```
|
||||
|
||||
# `env`
|
||||
|
||||
```c++
|
||||
bool is_interactive();
|
||||
std::optional<std::string> env(std::string name);
|
||||
std::map<std::string, std::string> env();
|
||||
```
|
||||
|
@ -2,6 +2,7 @@
|
||||
// # include <biu/atomic/atomic.tpp>
|
||||
// # include <biu/called_by.hpp>
|
||||
# include <biu/common.tpp>
|
||||
# include <biu/env.hpp>
|
||||
// # include <biu/concepts.tpp>
|
||||
// # include <biu/format.tpp>
|
||||
// # include <biu/logger.tpp>
|
||||
|
8
local/pkgs/biu/include/biu/env.hpp
Normal file
8
local/pkgs/biu/include/biu/env.hpp
Normal file
@ -0,0 +1,8 @@
|
||||
# pragma once
|
||||
# include <biu/common.hpp>
|
||||
|
||||
namespace biu::env
|
||||
{
|
||||
bool is_interactive();
|
||||
std::optional<std::string> env(std::string name);
|
||||
}
|
@ -5,8 +5,7 @@
|
||||
|
||||
namespace biu
|
||||
{
|
||||
std::regex literals::operator""_re(const char* str, std::size_t len)
|
||||
{ return std::regex{str, len}; }
|
||||
std::regex literals::operator""_re(const char* str, std::size_t len) { return std::regex{str, len}; }
|
||||
namespace common
|
||||
{
|
||||
void block_forever() { std::promise<void>().get_future().wait(); std::unreachable(); }
|
||||
@ -25,12 +24,14 @@ namespace biu
|
||||
if (stdin)
|
||||
{
|
||||
process = std::make_unique<bp::child>
|
||||
(program.string(), bp::args(args), bp::std_out > stdout, bp::std_err > stderr, bp::std_in < input, env);
|
||||
(program.string(), bp::args(args), bp::std_out > stdout, bp::std_err > stderr,
|
||||
bp::std_in < input, env);
|
||||
input << *stdin;
|
||||
input.pipe().close();
|
||||
}
|
||||
else process = std::make_unique<bp::child>
|
||||
(program.string(), bp::args(args), bp::std_out > stdout, bp::std_err > stderr, bp::std_in < bp::null, env);
|
||||
(program.string(), bp::args(args), bp::std_out > stdout, bp::std_err > stderr,
|
||||
bp::std_in < bp::null, env);
|
||||
process->wait();
|
||||
return
|
||||
{
|
||||
|
12
local/pkgs/biu/src/env.cpp
Normal file
12
local/pkgs/biu/src/env.cpp
Normal file
@ -0,0 +1,12 @@
|
||||
# include <biu.hpp>
|
||||
# include <boost/process.hpp>
|
||||
|
||||
namespace biu::env
|
||||
{
|
||||
bool is_interactive() { return isatty(fileno(stdin)); }
|
||||
std::optional<std::string> env(std::string name)
|
||||
{
|
||||
if (auto value = std::getenv(name.c_str()); !value) return std::nullopt;
|
||||
else return value;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user