-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(wip) feature: add diagnostic data to --version flag
- Loading branch information
1 parent
9f361b3
commit d015207
Showing
4 changed files
with
97 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include <exception> | ||
#include <fstream> | ||
|
||
#include "sysinfoaggregator.h" | ||
using namespace booktrack_cli; | ||
|
||
SysInfo SysInfoAggregator::GetSysInfo() { | ||
SysInfo value; | ||
std::ifstream input_file{"/etc/os-release"}; | ||
|
||
if (input_file.good()) { | ||
std::string line; | ||
while (getline(input_file, line)) { | ||
auto splitted = split_entries(line); | ||
if (splitted[0] == "NAME") { | ||
value.os_release_name = splitted[1]; | ||
} | ||
if (splitted[0] == "VERSION") { | ||
value.os_release_version = splitted[1]; | ||
} | ||
} | ||
input_file.close(); | ||
} else { | ||
throw std::runtime_error("Could not open file."); | ||
} | ||
|
||
return value; | ||
} | ||
|
||
std::vector<std::string> SysInfoAggregator::split_entries( | ||
const std::string& s) { | ||
std::vector<std::string> result; | ||
std::string::size_type start{0}; | ||
std::string::size_type position; | ||
do { | ||
position = s.find_first_of("=", start); | ||
result.push_back(s.substr(start, position - start)); | ||
start = position + 1; | ||
} while (position != std::string::npos); | ||
|
||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#ifndef BOOKTRACK_CLI_SYSINFOAGGREGATOR_H | ||
#define BOOKTRACK_CLI_SYSINFOAGGREGATOR_H | ||
|
||
#include <filesystem> | ||
#include <string> | ||
#include <vector> | ||
|
||
namespace fs = std::filesystem; | ||
|
||
namespace booktrack_cli { | ||
|
||
struct SysInfo { | ||
std::string os_release_name; | ||
std::string os_release_version; | ||
}; | ||
|
||
class SysInfoAggregator { | ||
public: | ||
explicit SysInfoAggregator(fs::path release_file) | ||
: release_file_{release_file} {}; | ||
|
||
/** | ||
* @brief Get the Sys Info object | ||
* | ||
* @return SysInfo | ||
* @throws std::runtime_error | ||
*/ | ||
SysInfo GetSysInfo(); | ||
|
||
private: | ||
std::vector<std::string> split_entries(const std::string& s); | ||
|
||
fs::path release_file_; | ||
}; | ||
} // namespace booktrack_cli | ||
|
||
#endif |