update cmd. improve encoding
This commit is contained in:
@ -143,7 +143,6 @@ namespace Unvirt::CmdHelper {
|
||||
|
||||
private:
|
||||
void GetCmdLine(std::string& u8cmd);
|
||||
bool HasOpenedFile(void);
|
||||
void PrintHelp(void);
|
||||
void PrintArgParseError(const std::deque<std::string>& cmd, size_t pos);
|
||||
void PrintCommonError(const char* u8_fmt, ...);
|
||||
@ -153,6 +152,12 @@ namespace Unvirt::CmdHelper {
|
||||
void ProcInfo(const std::deque<std::string>& cmd);
|
||||
void ProcLs(const std::deque<std::string>& cmd);
|
||||
void ProcItems(const std::deque<std::string>& cmd);
|
||||
void ProcEncoding(const std::deque<std::string>& cmd);
|
||||
void ProcTemp(const std::deque<std::string>& cmd);
|
||||
|
||||
bool HasOpenedFile(void);
|
||||
void ClearDocument(void);
|
||||
void PrintMinContextMsg(const std::string& msg);
|
||||
|
||||
CmdSplitter m_CmdSplitter;
|
||||
size_t m_PageLen;
|
||||
@ -161,132 +166,4 @@ namespace Unvirt::CmdHelper {
|
||||
LibCmo::CK2::CKFileDocument* m_Doc;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
|
||||
enum class CmdArgType {
|
||||
NONE,
|
||||
STRING,
|
||||
INT
|
||||
};
|
||||
|
||||
struct OptionDescription {
|
||||
std::string mLongName;
|
||||
char mShortName;
|
||||
CmdArgType mType;
|
||||
std::string mDescription;
|
||||
};
|
||||
|
||||
class OptionsDescription {
|
||||
public:
|
||||
OptionsDescription();
|
||||
OptionsDescription(const OptionsDescription&) = delete;
|
||||
OptionsDescription& operator=(const OptionsDescription&) = delete;
|
||||
~OptionsDescription();
|
||||
|
||||
/// <summary>
|
||||
/// Add an option
|
||||
/// </summary>
|
||||
/// <param name="fullname">The long name of this option. Should NOT be blank or NULL.</param>
|
||||
/// <param name="shortname">A single char for the short name of this option. Leave ZERO to omit this.</param>
|
||||
/// <param name="type">The value type of this option. Set to CmdArgType::NONE to indicate this is a switch (no value).</param>
|
||||
/// <param name="sescription">The description of this option. This can be NULL.</param>
|
||||
void AddOption(const char* fullname, char shortname, CmdArgType type, const char* sescription);
|
||||
void AddPositionalOption(const char* corresponding_longname);
|
||||
|
||||
OptionDescription* GetDescByLongName(const std::string& longname);
|
||||
OptionDescription* GetDescByShortName(char shortname);
|
||||
OptionDescription* GetDescByPosition(size_t pos);
|
||||
|
||||
void PrintHelp(FILE* f);
|
||||
private:
|
||||
std::unordered_map<std::string, OptionDescription> mLongNameDict;
|
||||
std::unordered_map<char, std::string> mShortNameMapping;
|
||||
std::vector<std::string> mPositionalArgMapping;
|
||||
};
|
||||
|
||||
struct AnyVariable {
|
||||
size_t mDataBasicSize;
|
||||
void* mData;
|
||||
};
|
||||
|
||||
class VariablesMap {
|
||||
private:
|
||||
std::unordered_map<std::string, AnyVariable> mDataPair;
|
||||
|
||||
public:
|
||||
VariablesMap();
|
||||
VariablesMap(const VariablesMap&) = delete;
|
||||
VariablesMap& operator=(const VariablesMap&) = delete;
|
||||
~VariablesMap();
|
||||
|
||||
void Clear(void);
|
||||
/// <summary>
|
||||
/// Add option key value pair.
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="t"></param>
|
||||
/// <param name="val"></param>
|
||||
/// <returns>return false when this opt is existed.</returns>
|
||||
bool AddPair(const std::string& name, CmdArgType t, const std::string& val);
|
||||
bool Contain(const char* opt) {
|
||||
if (opt == nullptr) throw std::invalid_argument("Invalid Option Name.");
|
||||
return mDataPair.contains(opt);
|
||||
}
|
||||
template<typename T>
|
||||
T* GetData(const char* opt) {
|
||||
if (opt == nullptr) throw std::invalid_argument("Invalid Option Name.");
|
||||
const auto search = mDataPair.find(opt);
|
||||
if (search == mDataPair.end()) return nullptr;
|
||||
|
||||
if (sizeof(T) > search->second.mDataBasicSize) throw std::invalid_argument("Memory Violation.");
|
||||
return reinterpret_cast<T*>(search->second.mData);
|
||||
}
|
||||
};
|
||||
|
||||
struct CmdRegisteryEntry {
|
||||
std::string mSubCmdDesc;
|
||||
OptionsDescription mOptDesc;
|
||||
std::function<void(OptionsDescription&, VariablesMap&)> mBindProc;
|
||||
};
|
||||
|
||||
class ExecEnvironment {
|
||||
public:
|
||||
ExecEnvironment();
|
||||
ExecEnvironment(const ExecEnvironment&) = delete;
|
||||
ExecEnvironment& operator=(const ExecEnvironment&) = delete;
|
||||
~ExecEnvironment();
|
||||
|
||||
void ProcLoad(OptionsDescription&, VariablesMap&);
|
||||
void ProcInfo(OptionsDescription&, VariablesMap&);
|
||||
void ProcClear(OptionsDescription&, VariablesMap&);
|
||||
void ProcExportSql(OptionsDescription&, VariablesMap&);
|
||||
private:
|
||||
LibCmo::CKFile* mVtFile;
|
||||
LibCmo::Utils::VirtoolsContext* mVtFileEnv;
|
||||
};
|
||||
|
||||
class InteractiveCmd {
|
||||
public:
|
||||
InteractiveCmd();
|
||||
InteractiveCmd(const InteractiveCmd&) = delete;
|
||||
InteractiveCmd& operator=(const InteractiveCmd&) = delete;
|
||||
~InteractiveCmd();
|
||||
|
||||
private:
|
||||
void GetCmdLine(std::string& u8cmd);
|
||||
void CmdParser(const std::vector<std::string>& args);
|
||||
void PrintHelp(FILE* f);
|
||||
|
||||
void ProcExit(OptionsDescription&, VariablesMap&);
|
||||
|
||||
std::unordered_map<std::string, CmdRegisteryEntry> mCmdDispatcher;
|
||||
CmdSplitter mCmdSplitter;
|
||||
ExecEnvironment mExecEnv;
|
||||
VariablesMap mVm;
|
||||
std::string mBlank;
|
||||
bool mExitRunFlag;
|
||||
};
|
||||
|
||||
*/
|
||||
}
|
Reference in New Issue
Block a user