From 664d97c1855ad7c37f416b30c3b26f27846e8863 Mon Sep 17 00:00:00 2001 From: JuergenGleiss Date: Fri, 3 Jun 2022 09:40:24 +0200 Subject: [PATCH] Feature/drogon ctl add namespce to view (#1245) drogon_ctl --namespace and --path-to-namespace is allowed. If both parameters are used the value of namespace will be set in front of path-to-namespace added an example into the template cmake.csp how to use the new optional parameter of drogon_create_views --- cmake/DrogonUtilities.cmake | 16 ++++++++++++++-- drogon_ctl/create.cc | 4 ++-- drogon_ctl/templates/cmake.csp | 4 ++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/cmake/DrogonUtilities.cmake b/cmake/DrogonUtilities.cmake index 11ac95a7..7cb97996 100644 --- a/cmake/DrogonUtilities.cmake +++ b/cmake/DrogonUtilities.cmake @@ -1,6 +1,6 @@ # ############################################################################## # function drogon_create_views(target source_path output_path -# [use_path_as_namespace]) +# [TRUE to use_path_as_namespace] [prefixed namespace]) # ############################################################################## function(drogon_create_views arg) if(ARGC LESS 3) @@ -27,15 +27,27 @@ function(drogon_create_views arg) "" outputFile ${f2}) + set(p2ns "") + if("${ARGV3}" STREQUAL "TRUE") + set(p2ns "--path-to-namespace") + endif() + if ( (ARGC EQUAL 5) AND ( NOT "${ARGV4}" STREQUAL "") ) + string(REPLACE "::" "_" nSpace ${ARGV4}) + set(outputFile "${nSpace}_${outputFile}") + set(ns -n ${ARGV4}) + else() + set(ns "") + endif() add_custom_command(OUTPUT ${ARGV2}/${outputFile}.h ${ARGV2}/${outputFile}.cc COMMAND drogon_ctl ARGS create view ${inFile} - --path-to-namespace + ${p2ns} -o ${ARGV2} + ${ns} DEPENDS ${cspFile} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} VERBATIM) diff --git a/drogon_ctl/create.cc b/drogon_ctl/create.cc index 574ce34b..67a2da4f 100644 --- a/drogon_ctl/create.cc +++ b/drogon_ctl/create.cc @@ -24,8 +24,8 @@ std::string create::detail() "Usage:drogon_ctl create " "[-options] \n\n" "drogon_ctl create view [-o ] [-n " - "]|[--path-to-namespace]//create HttpView source files " - "from csp files\n\n" + "] [--path-to-namespace] //create HttpView source files " + "from csp files, namespace is prefixed of path-to-namespace\n\n" "drogon_ctl create controller [-s] <[namespace::]class_name> //" "create HttpSimpleController source files\n\n" "drogon_ctl create controller -h <[namespace::]class_name> //" diff --git a/drogon_ctl/templates/cmake.csp b/drogon_ctl/templates/cmake.csp index cbaf5261..5a5c4bac 100644 --- a/drogon_ctl/templates/cmake.csp +++ b/drogon_ctl/templates/cmake.csp @@ -54,6 +54,10 @@ drogon_create_views(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/views # use the following line to create views with namespaces. # drogon_create_views(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/views # ${CMAKE_CURRENT_BINARY_DIR} TRUE) +# use the following line to create views with namespace CHANGE_ME prefixed +# and path namespaces. +# drogon_create_views(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/views +# ${CMAKE_CURRENT_BINARY_DIR} TRUE CHANGE_ME) target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}