Skip to content
This repository was archived by the owner on Dec 26, 2022. It is now read-only.

Commit 5270af8

Browse files
committed
feat: Impl help instruction display
Implement struct `ta_cli_argument_s` for saving information of instructions. `ta_cli_arg_value_t` is an enum for recognising the commands. And once calling the function `ta_usage()`, it will show all the currently available command.
1 parent 6aa9697 commit 5270af8

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

accelerator/BUILD

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,9 @@ cc_library(
6868
hdrs = ["errors.h"],
6969
visibility = ["//visibility:public"],
7070
)
71+
72+
cc_library(
73+
name = "message",
74+
srcs = ["message.c"],
75+
hdrs = ["message.h"],
76+
)

accelerator/message.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include "message.h"
2+
#include "stdio.h"
3+
4+
void ta_usage() {
5+
printf("tangle-accelerator usage:\n");
6+
for (int i = 0; i < cli_cmd_num; i++) {
7+
printf("--%-34s ", ta_cli_arguments_g[i].name);
8+
printf(" ");
9+
if (ta_cli_arguments_g[i].has_arg == REQUIRED_ARG) {
10+
printf(" arg ");
11+
} else if (ta_cli_arguments_g[i].has_arg == OPTIONAL_ARG) {
12+
printf("[arg]");
13+
} else {
14+
printf(" ");
15+
}
16+
printf(" %s \n", ta_cli_arguments_g[i].desc);
17+
}
18+
}

accelerator/message.h

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#ifndef ACCELERATOR_MESSAGE_H_
2+
#define ACCELERATOR_MESSAGE_H_
3+
4+
#ifdef __cplusplus
5+
extern "C" {
6+
#endif
7+
8+
typedef enum ta_cli_arg_value_e {
9+
HELP_CLI,
10+
11+
/** TA */
12+
TA_HOST_CLI,
13+
TA_PORT_CLI,
14+
TA_THREAD_COUNT_CLI,
15+
TA_VERSION_CLI,
16+
17+
/** IRI */
18+
IRI_HOST_CLI,
19+
IRI_PORT_CLI,
20+
21+
/** REDIS */
22+
REDIS_HOST_CLI,
23+
REDIS_PORT_CLI,
24+
25+
/** CONFIG */
26+
MILESTONE_DEPTH_CLI,
27+
MWM_CLI,
28+
SEED_CLI,
29+
} ta_cli_arg_value_t;
30+
31+
typedef enum ta_cli_arg_requirement_e {
32+
NO_ARG,
33+
REQUIRED_ARG,
34+
OPTIONAL_ARG
35+
} ta_cli_arg_requirement_t;
36+
37+
static struct ta_cli_argument_s {
38+
char* name;
39+
int val;
40+
char* desc;
41+
ta_cli_arg_requirement_t has_arg;
42+
} ta_cli_arguments_g[] = {
43+
{"ta-help", HELP_CLI, "Show tangle-accelerator usage.", NO_ARG}};
44+
45+
static const int cli_cmd_num =
46+
sizeof(ta_cli_arguments_g) / sizeof(struct ta_cli_argument_s);
47+
void ta_usage();
48+
#ifdef __cplusplus
49+
}
50+
#endif
51+
52+
#endif // ACCELERATOR_MESSAGE_H_

0 commit comments

Comments
 (0)