-
Notifications
You must be signed in to change notification settings - Fork 42
feat: add command execution support to dde-am #314
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
base: master
Are you sure you want to change the base?
Conversation
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.
Sorry @yixinshark, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: yixinshark The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
68ca09d to
4e342db
Compare
4e342db to
9fc4161
Compare
- Add CommandExecutor class for executing arbitrary commands via DBus - Refactor main() into handleList, handleExecuteCommand, handleLaunchApp - Add --command/-c option with --type, --run-id, --workdir parameters - Add validation to require appId when not using --command - Improve help text with Usage section and examples - Update documentation with command execution examples Log: add command execution support to dde-am
9fc4161 to
2aca98c
Compare
deepin pr auto review我来对这段代码进行审查,主要从语法逻辑、代码质量、性能和安全这几个方面进行分析:
具体改进建议: // commandexecutor.h 改进
class CommandExecutor {
public:
CommandExecutor() = default; // 添加默认构造函数
// 添加参数验证
bool isValid() const;
// ... 其他方法保持不变 ...
private:
// 添加验证方法
bool validateProgram() const;
bool validateWorkDir() const;
bool validateEnvironment() const;
};
// commandexecutor.cpp 改进
CommandExecutor::CommandExecutor() {
// 在构造函数中注册 DBus 类型
static bool typesRegistered = false;
if (!typesRegistered) {
registerComplexDbusType();
typesRegistered = true;
}
}
bool CommandExecutor::isValid() const {
return validateProgram() &&
validateWorkDir() &&
validateEnvironment();
}
bool CommandExecutor::validateProgram() const {
// 验证程序路径是否存在且可执行
QFileInfo info(m_program);
return info.exists() && info.isExecutable();
}
bool CommandExecutor::validateWorkDir() const {
if (m_workdir.isEmpty()) return true;
QFileInfo info(m_workdir);
return info.exists() && info.isDir();
}
bool CommandExecutor::validateEnvironment() const {
// 验证环境变量格式
for (const auto &env : m_environmentVariables) {
if (!env.contains('=') || env.startsWith('=')) {
return false;
}
}
return true;
}
DExpected<void> CommandExecutor::execute() {
if (!isValid()) {
return DUnexpected{emplace_tag::USE_EMPLACE, -1,
QString("Invalid command parameters")};
}
// ... 其余执行逻辑 ...
}
// main.cpp 改进
int handleExecuteCommand(const QCommandLineParser &parser,
const QCommandLineOption &executeOption,
const QCommandLineOption &typeOption,
const QCommandLineOption &runIdOption,
const QCommandLineOption &workdirOption,
const QCommandLineOption &envOption) {
CommandExecutor executor;
QString program = parser.value(executeOption);
if (program.isEmpty()) {
qCritical() << "Error: No program specified";
return 1;
}
// 验证程序路径
if (!QFileInfo(program).exists()) {
qCritical() << "Error: Program does not exist:" << program;
return 1;
}
executor.setProgram(program);
// ... 其余参数设置 ...
// 执行前验证
if (!executor.isValid()) {
qCritical() << "Error: Invalid command parameters";
return 1;
}
auto ret = executor.execute();
if (!ret) {
qWarning() << ret.error();
return ret.error().getErrorCode();
}
return 0;
}这些改进主要关注:
建议在后续开发中:
|
Log: add command execution support to dde-am