/* app/builder/KMBuildInit.h
 *
 * Copyright (C) 2023 OpenKylin, Inc
 */

#ifndef __KMBUILDINIT_H__
#define __KMBUILDINIT_H__

#include <optional>

#include "app/KMSubCommand.h"
#include "common/KMBuildinsUtils.h"

/**
 * @brief 	 构建目录树初始化
 * @note	 供kaiming-builder构建流程中调用
 */
class KMBuildInit : public KMSubCommand
{
    DECLARE_DYNCREATE(KMBuildInit);

public:
    KMBuildInit();
    virtual ~KMBuildInit();

    int despose(int argc, char **argv) override;

    /**
     * @brief : 检查app与runtime的base
     */
    void checkBase();

private:
    void init(int argc, char **argv);

    int run();

    void generateMetadata();

    /**
     * @brief : 解析base/runtime等的pref
     * @param : [in] pref, 格式如：top.openkylin.base/stable/2.0.0
     * @return: std::optional<KMRef>
     */ 
    static std::optional<KMRef> parsePref(const std::string& pref);

private:
    class Options;
    class Private;
    std::unique_ptr<Private> d;
};

#endif // !__KMBUILDINIT_H__
