Skip to content

Commit a4d098f

Browse files
committed
Add example
1 parent 81bd7ef commit a4d098f

4 files changed

Lines changed: 28 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
## CHANGELOG
22

3-
### v0.1.0
3+
### v0.1.0 (2020-05-31)
44

55
* Initial Release

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ if(NOT WIN32)
5353
set_target_properties(scriptexec PROPERTIES COMPILE_FLAGS "${X_CMAKE_C_FLAGS} -Wconversion")
5454
endif()
5555

56+
# example
57+
add_executable(example examples/example.c)
58+
target_link_libraries(example scriptexec)
59+
set_target_properties(example PROPERTIES COMPILE_FLAGS "${X_CMAKE_C_FLAGS}")
60+
5661
# tests
5762
enable_testing()
5863

README.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,13 @@ This library enables to invoke complex multi command scripts with a single C api
2121

2222
```c
2323
#include "scriptexec.h"
24+
#include <stdio.h>
2425

2526
int main()
2627
{
2728
// invoke the script with default options
2829
struct ScriptExecResult result = scriptexec_run("echo 1\necho 2\necho 3\necho 4");
29-
assert_num_equal(result.code, 0);
30-
assert_string_equal(result.out, "1\n2\n3\n4\n");
31-
assert_string_equal(result.err, "");
30+
printf("Code: %d\nOutput:\n%s\nError:\n%s\n", result.code, result.out, result.err);
3231

3332
// invoke the script with custom options
3433
struct ScriptExecOptions options = scriptexec_create_options();
@@ -38,10 +37,7 @@ int main()
3837
options.print_commands = true; // default false, if true will print every command before invocation
3938

4039
result = scriptexec_run_with_options("echo 1\necho 2\necho 3\necho 4", options);
41-
42-
assert_num_equal(result.code, 0);
43-
assert_string_equal(result.out, "1\n2\n3\n4\n");
44-
assert_string_equal(result.err, "");
40+
printf("Code: %d\nOutput:\n%s\nError:\n%s\n", result.code, result.out, result.err);
4541
}
4642
```
4743

examples/example.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include "scriptexec.h"
2+
#include <stdio.h>
3+
4+
int main()
5+
{
6+
// invoke the script with default options
7+
struct ScriptExecResult result = scriptexec_run("echo 1\necho 2\necho 3\necho 4");
8+
printf("Code: %d\nOutput:\n%s\nError:\n%s\n", result.code, result.out, result.err);
9+
10+
// invoke the script with custom options
11+
struct ScriptExecOptions options = scriptexec_create_options();
12+
options.runner = "bash"; // default is 'sh'
13+
options.working_directory = "./target"; // default to current working directory
14+
options.exit_on_error = true; // default true, will break script execution on any error
15+
options.print_commands = true; // default false, if true will print every command before invocation
16+
17+
result = scriptexec_run_with_options("echo 1\necho 2\necho 3\necho 4", options);
18+
printf("Code: %d\nOutput:\n%s\nError:\n%s\n", result.code, result.out, result.err);
19+
}

0 commit comments

Comments
 (0)