Skip to content

Commit 0ae65bf

Browse files
att
1 parent 3142524 commit 0ae65bf

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

src/consts/consts.flags.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#define IMPLEMENT_MAIN_FLAG "m | implement_main"
1212
#define MAIN_NAME_FLAG "n | main_name"
1313
#define MAIN_PATH_FLAG "p | main_path"
14+
#define SLEEP_TIME_FLAG "s | sleep_time"
1415
#define WATCH_FLAG "w | watch"
1516
#define HELP_FLAG "h | help"
1617

@@ -23,6 +24,7 @@
2324
#define MAIN_PATH_DESCRIPTION "The path of the main function (default: not set)"
2425
#define HELP_DESCRIPTION "Show the help message"
2526
#define WATCH_DESCRIPTION "Watch the project and generate the code when the project changes"
27+
#define SLEEP_TIME_DESCRIPTION "The time to sleep between each check (default: 0)"
2628
#define HELP_MESSAGE "Usage: silverchain [options]\nOptions:" \
2729
BLUE"\n -h, --help\t\t\t" GREEN HELP_DESCRIPTION RESET \
2830
BLUE"\n -s, --src\t\t\t" GREEN SRC_DESCRIPTION RESET \
@@ -33,4 +35,5 @@ BLUE"\n -m, --implement_main\t\t" GREEN IMPLEMENT_MAIN_DESCRIPTION RESET \
3335
BLUE"\n -n, --main_name\t\t" GREEN MAIN_NAME_DESCRIPTION RESET \
3436
BLUE"\n -p, --main_path\t\t" GREEN MAIN_PATH_DESCRIPTION RESET \
3537
BLUE"\n -w, --watch\t\t\t" GREEN WATCH_DESCRIPTION RESET \
38+
BLUE"\n -s, --sleep_time\t\t" GREEN SLEEP_TIME_DESCRIPTION RESET \
3639
"\n"

src/generation/func_declaration.generation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ void generate_code(
2727
const char *main_path
2828
);
2929

30-
void generate_code_in_watch_mode(const char *src,const char *import_dir,const char *project_short_cut,DtwStringArray *tags,bool implement_main,char *main_name,const char *main_path);
30+
void generate_code_in_watch_mode(const char *src,const char *import_dir,const char *project_short_cut,DtwStringArray *tags,bool implement_main,char *main_name,const char *main_path,int sleep_time);

src/generation/func_definition.generation.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ void generate_code(
120120
UniversalGarbage_free(garbage);
121121
}
122122

123-
void generate_code_in_watch_mode(const char *src,const char *import_dir,const char *project_short_cut,DtwStringArray *tags,bool implement_main,char *main_name,const char *main_path){
123+
void generate_code_in_watch_mode(const char *src,const char *import_dir,const char *project_short_cut,DtwStringArray *tags,bool implement_main,char *main_name,const char *main_path,int sleep_time){
124124
char *first = NULL;
125125
printf(MAKING_PROJECT_MESSAGE);
126126
generate_code(src,import_dir,project_short_cut,tags,implement_main,main_name,main_path);
@@ -142,7 +142,9 @@ void generate_code_in_watch_mode(const char *src,const char *import_dir,const ch
142142
first = NULL;
143143
}
144144
dtw.hash.free(hash);
145-
145+
if(sleep_time > 0){
146+
sleep(sleep_time);
147+
}
146148
}
147149

148150
if(first != NULL){

src/main.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,12 @@ int main(int argc,char *argv[]){
106106

107107
CliFlag *watch_flag = cli.entry.get_flag(entry,WATCH_FLAG,CLI_NOT_CASE_SENSITIVE);
108108
if(watch_flag->exist){
109-
generate_code_in_watch_mode(src,imports,project_short_cut,tags,implement_main,main_name,main_path);
109+
CliFlag *sleep_time_flag = cli.entry.get_flag(entry,SLEEP_TIME_FLAG,CLI_NOT_CASE_SENSITIVE);
110+
int sleep_time = 0;
111+
if(sleep_time_flag->exist){
112+
sleep_time = cli.flag.get_long(sleep_time_flag,0);
113+
}
114+
generate_code_in_watch_mode(src,imports,project_short_cut,tags,implement_main,main_name,main_path,sleep_time);
110115
}
111116

112117
if(!watch_flag->exist){

0 commit comments

Comments
 (0)