printPreview: Augea way of previewing config file

This commit is contained in:
Wvader 2022-11-02 19:17:51 +00:00
parent 99763104a2
commit 7ed1c3e8bb
1 changed files with 11 additions and 5 deletions

View File

@ -1,10 +1,11 @@
#include <iostream>
#include <exception>
#include <augeas.h>
#include <stdio.h>
#include <vector>
#include <map>
// This file is currently for testing and training using augeas with C++
// Testing and training using augeas with C++
// https://github.com/hercules-team/augeas/blob/master/tests/test-api.c
static const char *abs_top_srcdir;
@ -29,7 +30,8 @@ static void testGet() {
aug_close(aug);
}
static void readHostsFile() {
// This prints the actual file
static void printPreview(const std::string& matchPath, const std::string& filePath) {
struct augeas *aug;
int r;
char *s;
@ -39,8 +41,8 @@ static void readHostsFile() {
aug = aug_init(root, loadpath, AUG_NO_STDINC | AUG_NO_LOAD);
r = aug_load_file(aug, "/etc/hosts");
r = aug_preview(aug, "/files/etc/hosts/1", &s);
r = aug_load_file(aug, filePath.c_str());
r = aug_preview(aug, matchPath.c_str(), &s);
std::cout << s << std::endl;
@ -105,6 +107,10 @@ static void printAugTree(const std::string& matchPath, const std::string& filePa
int main(int argc, char *argv[]) {
//testGet();
printPreview("/files/etc/hosts/1", "/etc/hosts");
//printPreview("/files/etc/ssh/sshd_config/*", "/etc/ssh/sshd_config");
printAugTree("/files/etc/hosts/*", "/etc/hosts");
printAugTree("/files/etc/ssh/sshd_config/*", "/etc/ssh/sshd_config");