Skip to content

Consts / defaults #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.noformat
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Used by macros KOUT and KLOG : see inc/usage.hpp

Key KUL_GIT_CO
Type string
Default ""
Default "--depth 10 --recursive --shallow-submodules"
Description - Add string to git clone as arguments

Key KUL_SVN_CO
Expand Down
2 changes: 1 addition & 1 deletion inc/mkn/kul/assert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ struct Assert {
}
};

void abort_if(bool b) {
void inline abort_if(bool b) {
if (b) std::abort();
}

Expand Down
9 changes: 8 additions & 1 deletion inc/mkn/kul/os/nixish/env.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <algorithm>
#include <fstream>
#include <thread>
#include <cassert>

#include <limits.h>

Expand All @@ -65,7 +66,13 @@ inline std::string GET(char const* c, std::string default_ = "") {
char const* r = getenv(c);
return std::string(r ? r : default_);
}
inline void SET(char const* var, char const* val) { setenv(var, val, 1); }
inline void SET(char const* var, char const* val = nullptr) {
assert(var);
if (val and strlen(val) > 0)
setenv(var, val, 1);
else
unsetenv(var);
}
inline char SEP() { return ':'; }

inline std::string CWD() {
Expand Down
7 changes: 5 additions & 2 deletions inc/mkn/kul/os/win/env.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,11 @@ inline std::string GET(char const* c, std::string default_ = "") {
return default_;
}

inline void SET(char const* var, char const* val) {
_putenv(std::string(std::string(var) + "=" + std::string(val)).c_str());
inline void SET(char const* var, char const* val = nullptr) {
if (val and strlen(val) > 0)
_putenv(std::string(std::string(var) + "=" + std::string(val)).c_str());
else // unset
_putenv(std::string(std::string(var) + "=").c_str());
}

inline char SEP() { return ';'; }
Expand Down
3 changes: 2 additions & 1 deletion inc/mkn/kul/scm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ class Git : public SCM {
KTHROW(Exception) override {
Dir dr(d, true);
mkn::kul::Process p("git");
p << "clone" << mkn::kul::env::GET("KUL_GIT_CO") << r;
std::string defaults = "--depth 10 --recursive --shallow-submodules";
p << "clone" << mkn::kul::env::GET("KUL_GIT_CO", defaults) << r;
if (!v.empty()) p.arg("-b").arg(v);
try {
p.arg(d).start();
Expand Down
4 changes: 2 additions & 2 deletions inc/mkn/kul/yaml.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class File : public Item {
}
virtual ~File() {}
std::string const& file() const { return f; }
const virtual Validator validator() const = 0;
virtual Validator validator() const = 0;

protected:
void reload() KTHROW(Exception) {
Expand All @@ -178,7 +178,7 @@ class File : public Item {
File(std::string const& f) KTHROW(Exception) : f(f) { reload(); }

private:
const std::string f; // file
std::string const f; // file
};
} // namespace yaml
} // namespace kul
Expand Down