Skip to content

Commit

Permalink
add function to generate config from cmd line opts, for lua
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeck88 committed Nov 9, 2014
1 parent ca309d9 commit cd3e8cf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/commandline_options.cpp
Expand Up @@ -15,6 +15,12 @@
#include "commandline_options.hpp"
#include "global.hpp"

#include "config.hpp"
#include "formatter.hpp"
#include "log.hpp" // for logger, set_strict_severity, etc
#include "serialization/string_utils.hpp" // for split
#include "util.hpp" // for lexical_cast

#include <boost/any.hpp> // for any
#include <boost/foreach.hpp> // for auto_any_base, etc
#include <boost/program_options/cmdline.hpp>
Expand All @@ -25,11 +31,6 @@
#include <boost/program_options/variables_map.hpp> // for variables_map, etc
#include <boost/version.hpp> // for BOOST_VERSION
#include <iostream> // for operator<<, basic_ostream, etc
#include "formatter.hpp"
#include "log.hpp" // for logger, set_strict_severity, etc
#include "serialization/string_utils.hpp" // for split
#include "util.hpp" // for lexical_cast


namespace po = boost::program_options;

Expand Down Expand Up @@ -576,3 +577,17 @@ std::ostream& operator<<(std::ostream &os, const commandline_options& cmdline_op
os << cmdline_opts.visible_;
return os;
}

config commandline_options::to_config() const {
config ret;
if (server) {
ret["server"] = *server;
}
if (username) {
ret["username"] = *username;
}
if (password) {
ret["password"] = *password;
}
return ret;
}
4 changes: 4 additions & 0 deletions src/commandline_options.hpp
Expand Up @@ -35,6 +35,8 @@ class bad_commandline_tuple : public boost::program_options::error
const std::string& expected_format);
};

class config;

class commandline_options
{
/// To be used for printing help to the commandline.
Expand All @@ -43,6 +45,8 @@ friend std::ostream& operator<<(std::ostream &os, const commandline_options& cmd
public:
commandline_options(const std::vector<std::string>& args);

config to_config() const; /* Used by lua scrips. Not all of the options need to be exposed here, just those exposed to lua */

/// BitsPerPixel specified by --bpp option.
boost::optional<int> bpp;
/// Non-empty if --bunzip2 was given on the command line. Uncompresses a .bz2 file and exits.
Expand Down

0 comments on commit cd3e8cf

Please sign in to comment.