4 #include <boost/filesystem.hpp> 5 #include <boost/program_options.hpp> 7 #include "config/config.h" 9 #include "utilities/aktualizr_version.h" 11 namespace bpo = boost::program_options;
13 bpo::variables_map parse_options(
int argc,
char **argv) {
14 bpo::options_description description(
15 "A tool similar to wget that will do an HTTP get on the given URL using the device's configured credentials.");
19 description.add_options()
20 (
"help,h",
"print usage")
21 (
"version,v",
"Current aktualizr version")
22 (
"config,c", bpo::value<std::vector<boost::filesystem::path> >()->composing(),
"configuration file or directory")
23 (
"loglevel", bpo::value<int>(),
"set log level 0-5 (trace, debug, info, warning, error, fatal)")
24 (
"url,u", bpo::value<std::string>(),
"url to get");
27 bpo::variables_map vm;
28 std::vector<std::string> unregistered_options;
30 bpo::basic_parsed_options<char> parsed_options = bpo::command_line_parser(argc, argv).options(description).run();
31 bpo::store(parsed_options, vm);
33 if (vm.count(
"help") != 0) {
34 std::cout << description <<
'\n';
38 }
catch (
const bpo::required_option &ex) {
40 std::cout << ex.what() << std::endl << description;
42 }
catch (
const bpo::error &ex) {
43 std::cout << ex.what() << std::endl;
44 std::cout << description;
51 int main(
int argc,
char *argv[]) {
52 logger_init(isatty(1) == 1);
53 logger_set_threshold(boost::log::trivial::info);
55 bpo::variables_map commandline_map = parse_options(argc, argv);
59 Config config(commandline_map);
60 std::string body = aktualizrGet(config, commandline_map[
"url"].as<std::string>());
64 }
catch (
const std::exception &ex) {
65 LOG_ERROR << ex.what();
Configuration object for an aktualizr instance running on a Primary ECU.