Skip to content

Commit fdd35a7

Browse files
committed
0.1.18
1 parent c9dc89e commit fdd35a7

13 files changed

+84
-30
lines changed

CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ cmake_minimum_required(VERSION 3.23)
1111
# (3) Sync the download url in `README.md`.
1212
###############################################################################
1313
project(cmdout_sln
14-
VERSION 0.1.17
14+
VERSION 0.1.18
1515
)
1616
set(CMDOUT_VERSION ${PROJECT_VERSION})
1717

@@ -71,7 +71,7 @@ if (CMDOUT_ENABLE_DOXYGEN)
7171
set(DOXYGEN_SHOW_INCLUDE_FILES YES)
7272
set(DOXYGEN_BINARY_TOC YES)
7373
set(DOXYGEN_TOC_EXPAND YES)
74-
set(DOXYGEN_USE_MDFILE_AS_MAINPAGE "index.md")
74+
set(DOXYGEN_USE_MDFILE_AS_MAINPAGE "docs/index.md")
7575
message(DEBUG "PROJECT_SOURCE_DIR: ${PROJECT_SOURCE_DIR}")
7676
message(DEBUG "CMAKE_CURRENT_SOURCE_DIR: ${CMAKE_CURRENT_SOURCE_DIR}")
7777
doxygen_add_docs(cmdout_doxygen

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# myvas::cmdout
2-
The `myvas::cmdout` library provides facilities for executing shell commands and get their output before time runs out.
2+
The cmdout library provides facilities for executing shell commands and get their output before time runs out.
33

44
## Todo list
55
- By now, it works on Linux; but it should work on more platforms.
@@ -9,22 +9,22 @@ The `myvas::cmdout` library provides facilities for executing shell commands and
99
```
1010
include(FetchContent)
1111
FetchContent_Declare(cmdout
12-
URL https://github.com/myvas/cmdout/archive/refs/tags/0.1.13.tar.gz
12+
URL https://github.com/myvas/cmdout/archive/refs/tags/0.1.18.tar.gz
1313
DOWNLOAD_EXTRACT_TIMESTAMP ON
1414
)
1515
FetchContent_MakeAvailable(cmdout)
1616
17-
target_link_libraries(<your_target> PRIVATE myvas::cmdout)
17+
target_link_libraries(<your_target> PRIVATE cmdout)
1818
```
1919
### Include the header file
2020
```
21-
#include <cmdout.hpp>
21+
#include <cmdout/cmdout.hpp>
2222
```
2323

2424
### Examples
2525
C++17 on GNU/Linux Debian 11 (bullseye)
2626
```
27-
#include <cmdout_ext.hpp>
27+
#include <cmdout/cmdout_ext.hpp>
2828
#include <cassert>
2929
//...
3030
int main() {

benchmarks/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ include(cmake/benchmark.cmake)
1616
###########################
1717
add_executable(benchmarks "src/benchmarks.cpp")
1818
cmdout_enable_warnings(benchmarks)
19-
target_link_libraries(benchmarks PRIVATE myvas::cmdout benchmark::benchmark)
19+
target_link_libraries(benchmarks PRIVATE cmdout benchmark::benchmark)

benchmarks/src/benchmarks.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @file benchmarks.cpp
66
* @brief benchmarks for myvas::cmdout.
77
*/
8-
#include "cmdout.hpp"
8+
#include <cmdout/cmdout.hpp>
99

1010
#include <iostream>
1111

cmdout/include/cmdout/cmdout.hpp

+62-10
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
namespace myvas {
1717

18+
/**
19+
* @brief Default timeout 10 seconds.
20+
*/
1821
const int64_t CMDOUT_TIMEOUT_MILLISECONDS = 10 * 1000;
1922

2023
/**
@@ -32,7 +35,7 @@ class cmdout
3235
/**
3336
* @brief Gets the exit code after exec returned.
3437
*
35-
* The value is one of the following:
38+
* @return The value is one of the following:
3639
* - If cmd is empty, then a nonzero value if a shell is available, or 0 if
3740
* no shell is available.
3841
* - If a child process in cmd could not be created, or its status could not
@@ -43,23 +46,45 @@ class cmdout
4346
* last command in cmd.
4447
*/
4548
int status() const;
49+
50+
/**
51+
* @brief Sets the status value.
52+
*/
4653
cmdout& status(int);
4754

4855
/**
4956
* @brief Gets the content of stdout (file descriptor 1).
5057
*/
5158
std::string out() const;
59+
/**
60+
* @brief Sets the out string.
61+
*/
5262
cmdout& out(const std::string&);
5363

5464
/**
5565
* @brief Gets the shell command line.
5666
*/
5767
std::string cmd() const;
68+
/**
69+
* @brief Sets the cmd string.
70+
*/
5871
cmdout& cmd(const std::string&);
5972

73+
/**
74+
* @brief Gets the timeout duration in milliseconds.
75+
*/
6076
std::chrono::milliseconds timeout() const;
77+
/**
78+
* @brief Gets the timeout in milliseconds.
79+
*/
6180
int64_t timeout_ms() const;
81+
/**
82+
* @brief Sets the timeout.
83+
*/
6284
cmdout& timeout(std::chrono::milliseconds);
85+
/**
86+
* @brief Sets the timeout value.
87+
*/
6388
cmdout& timeout(int64_t);
6489

6590
/**
@@ -73,9 +98,6 @@ class cmdout
7398
*
7499
* @param cmd The cmd argument is a pointer to a null-terminated string
75100
* containing a shell command.
76-
*
77-
* @return The return value is a cmdout object, in which wraps the status code
78-
* and output string of the shell command.
79101
*/
80102
explicit cmdout(const std::string& cmd);
81103

@@ -88,9 +110,6 @@ class cmdout
88110
* containing a shell command.
89111
*
90112
* @param timeout_ms timeout in milliseconds. (If zero, defaults to 10 seconds)
91-
*
92-
* @return The return value is a cmdout object, in which wraps the status code
93-
* and output string of the shell command.
94113
*/
95114
explicit cmdout(const std::string& cmd, int64_t timeout_ms);
96115

@@ -102,44 +121,76 @@ class cmdout
102121
* containing a shell command.
103122
*
104123
* @param timeout timeout duration. (If zero, defaults to 10 seconds)
105-
*
106-
* @return The return value is a cmdout object, in which wraps the status code
107-
* and output string of the shell command.
108124
*/
109125
explicit cmdout(const std::string& cmd, std::chrono::milliseconds timeout);
110126

111127
/**
112128
* @brief Constructs an output.
113129
*
130+
* @param cmd The cmd argument is a pointer to a null-terminated string containing a shell command.
131+
* @param timeout timeout duration. (If zero, defaults to 10 seconds)
114132
* @param status EXIT_SUCCESS, EXIT_FAILURE or errno
133+
* @param out output string
134+
*
115135
* @see cerrno and cstdlib.
116136
*/
117137
explicit cmdout(const std::string& cmd, std::chrono::milliseconds timeout, int status, const std::string& out);
138+
/**
139+
* @brief Constructs an output.
140+
*
141+
* @param cmd The cmd argument is a pointer to a null-terminated string containing a shell command.
142+
* @param timeout_ms timeout. (If zero, defaults to 10 seconds)
143+
* @param status EXIT_SUCCESS, EXIT_FAILURE or errno
144+
* @param out output string
145+
*
146+
* @see cerrno and cstdlib.
147+
*/
118148
explicit cmdout(const std::string& cmd, int64_t timeout_ms, int status, const std::string& out);
119149

150+
/**
151+
* @brief Copy constructor.
152+
*/
120153
cmdout(const cmdout&);
154+
/**
155+
* @brief Copy assignment.
156+
*/
121157
cmdout& operator=(const cmdout&);
158+
/**
159+
* @brief Move constructor.
160+
*/
122161
cmdout(cmdout&&);
162+
/**
163+
* @brief Move assignment.
164+
*/
123165
cmdout& operator=(cmdout&&);
124166

167+
/**
168+
* @brief Destructor.
169+
*/
125170
virtual ~cmdout();
126171

127172
/**
128173
* @brief Execute a specified shell command with arguments initialized in this class.
174+
*
175+
* @return The return value is a cmdout reference, in which wraps the status code
176+
* and output string of the shell command.
129177
*/
130178
cmdout& exec();
131179
};
132180

133181
/**
134182
* @brief Execute a shell command specified in cmd.
135183
*
184+
* @param cmd The cmd argument is a pointer to a null-terminated string containing a shell command.
185+
*
136186
* @return Returns a cmdout object (without timeout)
137187
*/
138188
cmdout system(const std::string& cmd);
139189

140190
/**
141191
* @brief Execute a shell command specified in cmd and get its output before time runs out.
142192
*
193+
* @param cmd The cmd argument is a pointer to a null-terminated string containing a shell command.
143194
* @param timeout timeout duration, defaults to 10 seconds
144195
*
145196
* @return Returns a cmdout object
@@ -149,6 +200,7 @@ cmdout system_timeout(const std::string& cmd, std::chrono::milliseconds timeout)
149200
/**
150201
* @brief Execute a shell command specified in cmd and get its output before time runs out.
151202
*
203+
* @param cmd The cmd argument is a pointer to a null-terminated string containing a shell command.
152204
* @param timeout_ms timeout in milliseconds, defaults to 10 seconds
153205
*
154206
* @return Returns a cmdout object

cmdout/src/cmdout.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @file cmdout.cpp
66
* @brief Implementation of class myvas::cmdout.
77
*/
8-
#include "cmdout.hpp"
8+
#include <cmdout/cmdout.hpp>
99

1010
namespace myvas {
1111

cmdout/src/system.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @file system.cpp
66
* @brief Implementation of function myvas::system().
77
*/
8-
#include "cmdout.hpp"
8+
#include <cmdout/cmdout.hpp>
99

1010
#include <array>
1111
#include <future>

examples/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ target_sources(example_std_system_out PRIVATE "src/example_std_system_out.cpp")
1717

1818
add_executable(example_myvas_system)
1919
target_sources(example_myvas_system PRIVATE "src/example_myvas_system.cpp")
20-
target_link_libraries(example_myvas_system PRIVATE myvas::cmdout)
20+
target_link_libraries(example_myvas_system PRIVATE cmdout)
2121

2222
add_executable(example_myvas_cmdout)
2323
target_sources(example_myvas_cmdout PRIVATE "src/example_myvas_cmdout.cpp")
24-
target_link_libraries(example_myvas_cmdout PRIVATE myvas::cmdout)
24+
target_link_libraries(example_myvas_cmdout PRIVATE cmdout)

examples/src/example_myvas_cmdout.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @file example_myvas_cmdout.cpp
66
* @brief example for class myvas::cmdout.
77
*/
8-
#include <cmdout_ext.hpp>
8+
#include <cmdout/cmdout_ext.hpp>
99

1010
#include <iostream>
1111
#include <cassert>

examples/src/example_myvas_system.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @file example_myvas_system.cpp
66
* @brief example for function myvas::system().
77
*/
8-
#include <cmdout_ext.hpp>
8+
#include <cmdout/cmdout_ext.hpp>
99

1010
#include <iostream>
1111
#include <cassert>

tests/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ endfunction()
3737
# target tests
3838
###########################
3939
if(CMDOUT_BUILD_TESTS OR CMDOUT_BUILD_ALL)
40-
cmdout_prepare_test(tests myvas::cmdout)
40+
cmdout_prepare_test(tests cmdout)
4141
endif()

tests/src/test_myvas_cmdout.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
* @file test_myvas_cmdout.cpp
66
* @brief Unit test for class myvas::cmdout.
77
*/
8-
#include <catch2/catch_test_macros.hpp>
98

10-
#include <cmdout.hpp>
9+
#include <cmdout/cmdout.hpp>
10+
11+
#include <catch2/catch_test_macros.hpp>
1112

1213
TEST_CASE("myvas::cmdout") {
1314
SECTION("with default arguments") {

tests/src/test_myvas_system.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
* @file test_myvas_system.cpp
66
* @brief Unit test for function myvas::system().
77
*/
8-
#include <catch2/catch_test_macros.hpp>
98

10-
#include <cmdout.hpp>
9+
#include <cmdout/cmdout.hpp>
10+
11+
#include <catch2/catch_test_macros.hpp>
1112

1213
TEST_CASE("myvas::system") {
1314
SECTION("with exit 0") {

0 commit comments

Comments
 (0)