-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat:Subcommands support separate command id #24
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,10 @@ void CmdTableManager::InitCmdTable() { | |
std::unique_lock wl(mutex_); | ||
|
||
// admin | ||
std::unique_ptr<BaseCmd> configPtr = std::make_unique<CmdConfig>(kCmdNameConfig, -2); | ||
auto configPtr = std::make_unique<CmdConfig>(kCmdNameConfig, -2); | ||
configPtr->AddSubCmd(std::make_unique<CmdConfigGet>("get", -3)); | ||
configPtr->AddSubCmd(std::make_unique<CmdConfigSet>("set", -4)); | ||
|
||
cmds_->insert(std::make_pair(kCmdNameConfig, std::move(configPtr))); | ||
|
||
// kv | ||
|
@@ -31,15 +34,22 @@ void CmdTableManager::InitCmdTable() { | |
cmds_->insert(std::make_pair(kCmdNameSet, std::move(setPtr))); | ||
} | ||
|
||
BaseCmd* CmdTableManager::GetCommand(const std::string& cmdName) { | ||
std::pair<BaseCmd*, CmdRes::CmdRet> CmdTableManager::GetCommand(const std::string& cmdName, CmdContext& ctx) { | ||
std::shared_lock rl(mutex_); | ||
|
||
auto cmd = cmds_->find(cmdName); | ||
|
||
if (cmd == cmds_->end()) { | ||
return nullptr; | ||
return std::pair(nullptr, CmdRes::kSyntaxErr); | ||
} | ||
|
||
if (cmd->second->HasSubCommand()) { | ||
if (ctx.argv_.size() < 2) { | ||
return std::pair(nullptr, CmdRes::kInvalidParameter); | ||
} | ||
return std::pair(cmd->second->GetSubCmd(ctx.argv_[1]), CmdRes::kSyntaxErr); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里没太明白逻辑,当没有subcommand时,状态应该返回 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 在调用 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 好嘞,谢谢~ |
||
} | ||
return cmd->second.get(); | ||
return std::pair(cmd->second.get(), CmdRes::kSyntaxErr); | ||
} | ||
|
||
bool CmdTableManager::CmdExist(const std::string& cmd) const { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里的判断条件应该是反了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
对,这里是判断错了