Program Listing for File options.hpp

Return to documentation for file (include/email/options.hpp)

// Copyright 2020-2021 Christophe Bedard
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef EMAIL__OPTIONS_HPP_
#define EMAIL__OPTIONS_HPP_

#include <chrono>
#include <memory>
#include <optional>  // NOLINT cpplint mistakes <optional> for a C system header
#include <regex>
#include <string>

#include "rcpputils/filesystem_helper.hpp"
#include "yaml-cpp/yaml.h"

#include "email/email/info.hpp"
#include "email/log.hpp"
#include "email/visibility_control.hpp"

namespace email
{


class Options
{
public:

  EMAIL_PUBLIC
  Options(
    std::optional<UserInfo::SharedPtrConst> user_info,
    std::optional<EmailRecipients::SharedPtrConst> recipients,
    const bool curl_verbose,
    const bool intraprocess,
    const std::optional<std::chrono::nanoseconds> polling_period);

  EMAIL_PUBLIC
  ~Options();


  EMAIL_PUBLIC
  std::optional<UserInfo::SharedPtrConst>
  get_user_info() const;


  EMAIL_PUBLIC
  std::optional<EmailRecipients::SharedPtrConst>
  get_recipients() const;


  EMAIL_PUBLIC
  bool
  curl_verbose() const;


  EMAIL_PUBLIC
  bool
  intraprocess() const;


  EMAIL_PUBLIC
  std::optional<std::chrono::nanoseconds>
  polling_period() const;


  static
  std::optional<std::shared_ptr<Options>>
  parse_options_from_args(int argc, char const * const argv[]);


  static
  std::optional<std::shared_ptr<Options>>
  parse_options_from_file();


  EMAIL_PUBLIC
  static
  std::optional<std::shared_ptr<Options>>
  yaml_to_options(YAML::Node);


  static
  std::optional<std::shared_ptr<Options>>
  parse_options_file(const rcpputils::fs::path & file_path);

private:

  static
  std::optional<std::shared_ptr<Options>>
  yaml_to_options_impl(YAML::Node);

  static
  std::shared_ptr<Logger>
  logger();

  std::optional<UserInfo::SharedPtrConst> user_info_;
  std::optional<EmailRecipients::SharedPtrConst> recipients_;
  const bool curl_verbose_;
  const bool intraprocess_;
  const std::optional<std::chrono::nanoseconds> polling_period_;

  static constexpr const char * ENV_VAR_CURL_VERBOSE = "EMAIL_CURL_VERBOSE";
  static constexpr const char * ENV_VAR_CONFIG_FILE = "EMAIL_CONFIG_FILE";
  static constexpr const char * ENV_VAR_CONFIG_FILE_DEFAULT_PATH =
    "EMAIL_CONFIG_FILE_DEFAULT_PATH";
  static constexpr const char * CONFIG_FILE_DEFAULT_NAME = "email.yml";
  static constexpr const char * USAGE_CLI_ARGS =
    "usage: HOST_SMTP HOST_IMAP EMAIL PASSWORD EMAIL_TO [-v|--curl-verbose]";
};

}  // namespace email

#endif  // EMAIL__OPTIONS_HPP_