/* common/KMOptions.h
 *
 * Copyright (C) 2023 OpenKylin, Inc
 */

#ifndef __KMOPTIONS_H__
#define __KMOPTIONS_H__

#include <boost/program_options.hpp>

namespace opt = boost::program_options;

/**
 * @brief 	 命令行选项基类
 */
class KMOptions
{
public:
    KMOptions();
    virtual ~KMOptions();

    int getPositionalOptionIndex(int numOfPositionalOption = 1);
    void parseCommandLine(int argc, char **argv);

protected:
    /**
     * m_optionsDescription所拥有的对象必需在子类中构建出来，因为其usage说明只能在构建时指明
     */
    virtual void preParseHook() = 0;
    virtual void postParseHook() {}
    virtual void showUsage() const;

    void checkOption(const opt::variables_map &varsMap, const char *longOption, const char *shortOption, bool &isSet);
    void showCmdline() const;

protected:
    int m_argc;
    char **m_argv;

    std::unique_ptr<opt::options_description> m_optionsDescription;
    std::unique_ptr<opt::positional_options_description> m_optionsPositionalDescription;
    std::unique_ptr<opt::options_description> m_optionsShowDescription;
    opt::variables_map m_varsMap;
};

#endif // !__KMOPTIONS_H__
