Sequoia
Loading...
Searching...
No Matches
ShellCommands.hpp
Go to the documentation of this file.
1
2// Copyright Oliver J. Rosten 2021. //
3// Distributed under the GNU GENERAL PUBLIC LICENSE, Version 3.0. //
4// (See accompanying file LICENSE.md or copy at //
5// https://www.gnu.org/licenses/gpl-3.0.en.html) //
7
8#pragma once
9
14#include <filesystem>
15#include <optional>
16
17namespace sequoia::runtime
18{
20 {
21 public:
22 enum class append_mode { no, yes };
23
24 shell_command() = default;
25
26 shell_command(std::string cmd) : m_Command{std::move(cmd)}
27 {}
28
29 shell_command(std::string_view preamble, std::string cmd, const std::filesystem::path& output, append_mode app = append_mode::no);
30
31 [[nodiscard]]
32 bool empty() const noexcept
33 {
34 return m_Command.empty();
35 }
36
37 [[nodiscard]]
38 const std::string& string() const noexcept
39 {
40 return m_Command;
41 }
42
43 [[nodiscard]]
44 friend bool operator==(const shell_command&, const shell_command&) noexcept = default;
45
46 [[nodiscard]]
47 friend shell_command operator&&(const shell_command& lhs, const shell_command& rhs)
48 {
49 return rhs.empty() ? lhs :
50 lhs.empty() ? rhs :
51 std::string{lhs.m_Command}.append("&&").append(rhs.m_Command);
52 }
53
54 [[nodiscard]]
55 friend shell_command operator&&(const shell_command& lhs, std::string rhs)
56 {
57 return lhs && shell_command{std::move(rhs)};
58 }
59
60 friend void invoke(const shell_command& cmd);
61 private:
62 std::string m_Command;
63
64 shell_command(std::string cmd, const std::filesystem::path& output, append_mode app);
65 };
66
67 [[nodiscard]]
68 shell_command cd_cmd(const std::filesystem::path& dir);
69}
Definition: ShellCommands.hpp:20