iceberg-cpp
Loading...
Searching...
No Matches
cmd_util.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#pragma once
21
22#include <filesystem>
23#include <map>
24#include <string>
25#include <vector>
26
29
30namespace iceberg {
31
33class Command {
34 public:
35 explicit Command(std::string program);
36
38 Command& Arg(std::string arg);
39
41 Command& Args(const std::vector<std::string>& args);
42
44 Command& CurrentDir(const std::filesystem::path& path);
45
47 Command& Env(const std::string& key, const std::string& val);
48
51 void RunCommand(const std::string& desc) const;
52
53 private:
54 std::string program_;
55 std::vector<std::string> args_;
56 std::filesystem::path cwd_;
57 std::map<std::string, std::string> env_vars_;
58
60 std::string FormatArgs() const;
61};
62
63} // namespace iceberg
A shell command builder and executor for tests.
Definition cmd_util.h:33
Command & Args(const std::vector< std::string > &args)
Add multiple arguments at once.
Definition cmd_util.cc:42
Command & Arg(std::string arg)
Add a single argument.
Definition cmd_util.cc:37
Command & Env(const std::string &key, const std::string &val)
Set an environment variable for the command.
Definition cmd_util.cc:52
void RunCommand(const std::string &desc) const
Execute the command and print logs.
Definition cmd_util.cc:57
Command & CurrentDir(const std::filesystem::path &path)
Set the current working directory for the command.
Definition cmd_util.cc:47