Skip to content

Commit c03a3df

Browse files
MouhKMouhamad Kebe
andauthored
added -o|--output option to drogon_ctl create models (#2304)
Co-authored-by: Mouhamad Kebe <[email protected]>
1 parent d6a33f9 commit c03a3df

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44

55
## [Unreleased]
66

7+
### Added
8+
9+
- dg_ctl create models new command line option -o | --output
10+
711
## [1.9.10] - 2025-02-20
812

913
### API changes list

drogon_ctl/create.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ std::string create::detail()
4242
"create a plugin named class_name\n\n"
4343
"drogon_ctl create project <project_name> //"
4444
"create a project named project_name\n\n"
45-
"drogon_ctl create model <model_path> [--table=<table_name>] [-f]//"
45+
"drogon_ctl create model <model_path> [-o <output path>] "
46+
"[--table=<table_name>] [-f]//"
4647
"create model classes in model_path\n";
4748
}
4849

drogon_ctl/create_model.cc

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,7 @@ void create_model::createModel(const std::string &path,
826826
auto restfulApiConfig = config["restful_api_controllers"];
827827
auto relationships = getRelationships(config["relationships"]);
828828
auto convertMethods = getConvertMethods(config["convert"]);
829+
drogon::utils::createPath(path);
829830
if (dbType == "postgresql")
830831
{
831832
#if USE_POSTGRESQL
@@ -1173,7 +1174,9 @@ void create_model::createModel(const std::string &path,
11731174
try
11741175
{
11751176
infile >> configJsonRoot;
1176-
createModel(path, configJsonRoot, singleModelName);
1177+
createModel(outputPath_.empty() ? path : outputPath_,
1178+
configJsonRoot,
1179+
singleModelName);
11771180
}
11781181
catch (const std::exception &exception)
11791182
{
@@ -1211,6 +1214,21 @@ void create_model::handleCommand(std::vector<std::string> &parameters)
12111214
break;
12121215
}
12131216
}
1217+
for (auto iter = parameters.begin(); iter != parameters.end(); ++iter)
1218+
{
1219+
auto &file = *iter;
1220+
if (file == "-o" || file == "--output")
1221+
{
1222+
iter = parameters.erase(iter);
1223+
if (iter != parameters.end())
1224+
{
1225+
outputPath_ = *iter;
1226+
iter = parameters.erase(iter);
1227+
}
1228+
continue;
1229+
}
1230+
}
1231+
12141232
for (auto const &path : parameters)
12151233
{
12161234
createModel(path, singleModelName);

drogon_ctl/create_model.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,5 +429,6 @@ class create_model : public DrObject<create_model>, public CommandHandler
429429
const Json::Value &restfulApiConfig);
430430
std::string dbname_;
431431
bool forceOverwrite_{false};
432+
std::string outputPath_;
432433
};
433434
} // namespace drogon_ctl

0 commit comments

Comments
 (0)