mirror of
https://gitee.com/acl-dev/acl.git
synced 2024-11-29 18:37:41 +08:00
App wizard can create service in commandline mode.
This commit is contained in:
parent
124eea3dfb
commit
2275e50a59
@ -102,34 +102,40 @@ static bool create_proc(file_tmpl& tmpl)
|
||||
return tmpl.files_copy(name, tab);
|
||||
}
|
||||
|
||||
static bool create_service(file_tmpl& tmpl)
|
||||
static bool create_service(file_tmpl& tmpl, const char* type)
|
||||
{
|
||||
printf("choose master_service type:\r\n");
|
||||
printf(" t: for master_threads\r\n"
|
||||
" f: for master_fiber\r\n"
|
||||
" p: for master_proc\r\n");
|
||||
printf(">");
|
||||
fflush(stdout);
|
||||
|
||||
char buf[256];
|
||||
int n = acl_vstream_gets_nonl(ACL_VSTREAM_IN, buf, sizeof(buf));
|
||||
if (n == ACL_VSTREAM_EOF) {
|
||||
return false;
|
||||
} else if (strcasecmp(buf, "t") == 0) {
|
||||
if (type == NULL || *type == 0) {
|
||||
printf("choose master_service type:\r\n");
|
||||
printf(" t: for master_threads\r\n"
|
||||
" f: for master_fiber\r\n"
|
||||
" p: for master_proc\r\n");
|
||||
printf(">");
|
||||
fflush(stdout);
|
||||
|
||||
int n = acl_vstream_gets_nonl(ACL_VSTREAM_IN, buf, sizeof(buf));
|
||||
if (n == ACL_VSTREAM_EOF) {
|
||||
return false;
|
||||
}
|
||||
|
||||
type = buf;
|
||||
}
|
||||
|
||||
if (strcasecmp(type, "t") == 0) {
|
||||
create_threads(tmpl);
|
||||
} else if (strcasecmp(buf, "p") == 0) {
|
||||
} else if (strcasecmp(type, "p") == 0) {
|
||||
create_proc(tmpl);
|
||||
} else if (strcasecmp(buf, "f") == 0) {
|
||||
} else if (strcasecmp(type, "f") == 0) {
|
||||
create_fiber(tmpl);
|
||||
} else {
|
||||
printf("invalid: %s\r\n", buf);
|
||||
printf("invalid type: %s\r\n", type);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool create_http_servlet(file_tmpl& tmpl)
|
||||
static bool create_http_servlet(file_tmpl& tmpl, const char* type)
|
||||
{
|
||||
tpl_t* tpl = tmpl.open_tpl("http_servlet.cpp");
|
||||
if (tpl == NULL) {
|
||||
@ -158,50 +164,49 @@ static bool create_http_servlet(file_tmpl& tmpl)
|
||||
tpl_free(tpl);
|
||||
|
||||
// 设置服务器模板类型
|
||||
return create_service(tmpl);
|
||||
return create_service(tmpl, type);
|
||||
}
|
||||
|
||||
void http_creator()
|
||||
void http_creator(const char* name, const char* type)
|
||||
{
|
||||
bool loop;
|
||||
file_tmpl tmpl;
|
||||
|
||||
if (name && *name && type && *type) {
|
||||
loop = true;
|
||||
} else {
|
||||
loop = false;
|
||||
}
|
||||
|
||||
// 设置源程序所在目录
|
||||
tmpl.set_path_from("tmpl/http");
|
||||
|
||||
while (true) {
|
||||
printf("please input your program name: ");
|
||||
fflush(stdout);
|
||||
|
||||
char buf[256];
|
||||
int n;
|
||||
|
||||
n = acl_vstream_gets_nonl(ACL_VSTREAM_IN, buf, sizeof(buf));
|
||||
if (n == ACL_VSTREAM_EOF) {
|
||||
break;
|
||||
if (name == NULL || *name == 0) {
|
||||
printf("please input your program name: ");
|
||||
fflush(stdout);
|
||||
n = acl_vstream_gets_nonl(ACL_VSTREAM_IN, buf, sizeof(buf));
|
||||
if (n == ACL_VSTREAM_EOF) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (n == 0) {
|
||||
acl::safe_snprintf(buf, sizeof(buf), "http_demo");
|
||||
}
|
||||
|
||||
name = buf;
|
||||
}
|
||||
|
||||
if (n == 0) {
|
||||
acl::safe_snprintf(buf, sizeof(buf), "http_demo");
|
||||
}
|
||||
tmpl.set_project_name(name);
|
||||
|
||||
tmpl.set_project_name(buf);
|
||||
// 创建目录
|
||||
tmpl.create_dirs();
|
||||
|
||||
printf("please choose one http application type:\r\n");
|
||||
printf("s: http servlet\r\n");
|
||||
printf(">");
|
||||
fflush(stdout);
|
||||
|
||||
n = acl_vstream_gets_nonl(ACL_VSTREAM_IN, buf, sizeof(buf));
|
||||
if (n == ACL_VSTREAM_EOF) {
|
||||
break;
|
||||
} else if (strcasecmp(buf, "s") == 0) {
|
||||
tmpl.create_common();
|
||||
create_http_servlet(tmpl);
|
||||
} else {
|
||||
printf("unknown flag: %s\r\n", buf);
|
||||
}
|
||||
tmpl.create_common();
|
||||
create_http_servlet(tmpl, type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
void http_creator();
|
||||
void http_creator(const char* name, const char* type);
|
||||
|
@ -137,12 +137,19 @@ static bool create_master_udp(file_tmpl& tmpl)
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
return tmpl. files_copy(name, tab);
|
||||
return tmpl.files_copy(name, tab);
|
||||
}
|
||||
|
||||
void master_creator()
|
||||
void master_creator(const char* name, const char* type)
|
||||
{
|
||||
file_tmpl tmpl;
|
||||
bool loop;
|
||||
|
||||
if (name && *name && type && *type) {
|
||||
loop = true;
|
||||
} else {
|
||||
loop = false;
|
||||
}
|
||||
|
||||
// 设置源程序所在目录
|
||||
tmpl.set_path_from("tmpl/master");
|
||||
@ -151,73 +158,88 @@ void master_creator()
|
||||
char buf[256];
|
||||
int n;
|
||||
|
||||
printf("please input your program name: ");
|
||||
fflush(stdout);
|
||||
if (name == NULL || *name == 0) {
|
||||
printf("please input your program name: ");
|
||||
fflush(stdout);
|
||||
|
||||
n = acl_vstream_gets_nonl(ACL_VSTREAM_IN, buf, sizeof(buf));
|
||||
if (n == ACL_VSTREAM_EOF) {
|
||||
break;
|
||||
n = acl_vstream_gets_nonl(ACL_VSTREAM_IN, buf, sizeof(buf));
|
||||
if (n == ACL_VSTREAM_EOF) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (n == 0) {
|
||||
acl::safe_snprintf(buf, sizeof(buf), "master_service");
|
||||
}
|
||||
name = buf;
|
||||
}
|
||||
|
||||
if (n == 0) {
|
||||
acl::safe_snprintf(buf, sizeof(buf), "master_service");
|
||||
}
|
||||
// 设置项目名称, 一般与服务程序名相同
|
||||
tmpl.set_project_name(name);
|
||||
|
||||
tmpl.set_project_name(buf);
|
||||
// 创建目录
|
||||
tmpl.create_dirs();
|
||||
|
||||
printf("choose master_service type:\r\n");
|
||||
printf(" t: for master_threads\r\n"
|
||||
" p: for master_proc\r\n"
|
||||
" a: for master_aio\t\n"
|
||||
" g: for master_trigger\r\n"
|
||||
" r: for master_rpc\r\n"
|
||||
" u: for master_udp\r\n"
|
||||
" f: for master_fiber\r\n"
|
||||
" o: for other service\r\n"
|
||||
" s: skip choose, try again\r\n");
|
||||
printf(">");
|
||||
fflush(stdout);
|
||||
if (type == NULL || *type == 0) {
|
||||
printf("choose master_service type:\r\n");
|
||||
printf(" t: for master_threads\r\n"
|
||||
" p: for master_proc\r\n"
|
||||
" a: for master_aio\t\n"
|
||||
" g: for master_trigger\r\n"
|
||||
" r: for master_rpc\r\n"
|
||||
" u: for master_udp\r\n"
|
||||
" f: for master_fiber\r\n"
|
||||
" o: for other service\r\n"
|
||||
" s: skip choose, try again\r\n");
|
||||
printf(">");
|
||||
fflush(stdout);
|
||||
|
||||
n = acl_vstream_gets_nonl(ACL_VSTREAM_IN, buf, sizeof(buf));
|
||||
if (n == ACL_VSTREAM_EOF) {
|
||||
break;
|
||||
} else if (strcasecmp(buf, "t") == 0) {
|
||||
n = acl_vstream_gets_nonl(ACL_VSTREAM_IN, buf, sizeof(buf));
|
||||
if (n == ACL_VSTREAM_EOF) {
|
||||
break;
|
||||
}
|
||||
|
||||
type = buf;
|
||||
}
|
||||
|
||||
if (strcasecmp(type, "t") == 0) {
|
||||
tmpl.create_common();
|
||||
create_master_threads(tmpl);
|
||||
break;
|
||||
} else if (strcasecmp(buf, "p") == 0) {
|
||||
} else if (strcasecmp(type, "p") == 0) {
|
||||
tmpl.create_common();
|
||||
create_master_proc(tmpl);
|
||||
break;
|
||||
} else if (strcasecmp(buf, "a") == 0) {
|
||||
} else if (strcasecmp(type, "a") == 0) {
|
||||
tmpl.create_common();
|
||||
create_master_aio(tmpl);
|
||||
break;
|
||||
} else if (strcasecmp(buf, "r") == 0) {
|
||||
} else if (strcasecmp(type, "r") == 0) {
|
||||
tmpl.create_common();
|
||||
create_master_rpc(tmpl);
|
||||
break;
|
||||
} else if (strcasecmp(buf, "g") == 0) {
|
||||
} else if (strcasecmp(type, "g") == 0) {
|
||||
tmpl.create_common();
|
||||
create_master_trigger(tmpl);
|
||||
break;
|
||||
} else if (strcasecmp(buf, "u") == 0) {
|
||||
} else if (strcasecmp(type, "u") == 0) {
|
||||
tmpl.create_common();
|
||||
create_master_udp(tmpl);
|
||||
break;
|
||||
} else if (strcasecmp(buf, "f") == 0) {
|
||||
} else if (strcasecmp(type, "f") == 0) {
|
||||
tmpl.create_common();
|
||||
create_master_fiber(tmpl);
|
||||
break;
|
||||
} else if (strcasecmp(buf, "o") == 0) {
|
||||
} else if (strcasecmp(type, "o") == 0) {
|
||||
tmpl.create_other();
|
||||
break;
|
||||
} else if (strcasecmp(buf, "s") == 0) {
|
||||
} else if (strcasecmp(type, "s") == 0) {
|
||||
break;
|
||||
} else {
|
||||
printf("unknown ch: %s\r\n", buf);
|
||||
printf("unknown ch: %s\r\n", type);
|
||||
}
|
||||
|
||||
if (!loop) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
void master_creator();
|
||||
void master_creator(const char* name, const char* type);
|
||||
|
@ -3,6 +3,9 @@
|
||||
|
||||
#include "stdafx.h"
|
||||
#include <stdio.h>
|
||||
#if !defined(_WIN32) && !defined(_WIN64)
|
||||
# include <getopt.h>
|
||||
#endif
|
||||
#include "master_creator.h"
|
||||
#include "http_creator.h"
|
||||
|
||||
@ -10,27 +13,79 @@ static void create_db()
|
||||
{
|
||||
}
|
||||
|
||||
static int create_master_service(const char* name, const char* type)
|
||||
{
|
||||
master_creator(name, type);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int create_http_service(const char* name, const char* type)
|
||||
{
|
||||
http_creator(name, type);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void usage(const char* procname)
|
||||
{
|
||||
printf("usage: %s -h [help]\r\n"
|
||||
" -n program_name\r\n"
|
||||
" -t service_type [ t -> master_threads, p -> master_proc, f -> master_fiber, u -> master_udp, o -> master_other ]\r\n"
|
||||
" -a application_type [ http | master, default: master ]\r\n"
|
||||
, procname);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
(void) argc, (void) argv;
|
||||
int ch;
|
||||
acl::string name, type, app("master");
|
||||
|
||||
while ((ch = getopt(argc, argv, "hn:t:a:")) > 0) {
|
||||
switch (ch) {
|
||||
case 'h':
|
||||
usage(argv[0]);
|
||||
return 0;
|
||||
case 'n':
|
||||
name = optarg;
|
||||
break;
|
||||
case 't':
|
||||
type = optarg;
|
||||
break;
|
||||
case 'a':
|
||||
app = optarg;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
acl::acl_cpp_init();
|
||||
|
||||
if (!name.empty() && !type.empty()) {
|
||||
if (app == "master") {
|
||||
return create_master_service(name, type);
|
||||
} else if (app == "http") {
|
||||
return create_http_service(name, type);
|
||||
}
|
||||
}
|
||||
|
||||
while (true) {
|
||||
char buf[256];
|
||||
|
||||
printf("select one below:\r\n");
|
||||
printf("m: master_service; d: db; h: http; q: exit\r\n");
|
||||
printf(">"); fflush(stdout);
|
||||
|
||||
char buf[256];
|
||||
int n = acl_vstream_gets_nonl(ACL_VSTREAM_IN, buf, sizeof(buf));
|
||||
if (n == ACL_VSTREAM_EOF) {
|
||||
break;
|
||||
} else if (strcasecmp(buf, "m") == 0) {
|
||||
master_creator();
|
||||
}
|
||||
|
||||
if (strcasecmp(buf, "m") == 0) {
|
||||
master_creator(NULL, NULL);
|
||||
} else if (strcasecmp(buf, "d") == 0) {
|
||||
create_db();
|
||||
} else if (strcasecmp(buf, "h") == 0) {
|
||||
http_creator();
|
||||
http_creator(NULL, NULL);
|
||||
} else if (strcasecmp(buf, "q") == 0) {
|
||||
break;
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user