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

Commit

Permalink
feat: Impl help instruction display
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
howjmay committed Apr 10, 2019
1 parent 6aa9697 commit 5270af8
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
6 changes: 6 additions & 0 deletions accelerator/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,9 @@ cc_library(
hdrs = ["errors.h"],
visibility = ["//visibility:public"],
)

cc_library(
name = "message",
srcs = ["message.c"],
hdrs = ["message.h"],
)
18 changes: 18 additions & 0 deletions accelerator/message.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "message.h"
#include "stdio.h"

void ta_usage() {
printf("tangle-accelerator usage:\n");
for (int i = 0; i < cli_cmd_num; i++) {
printf("--%-34s ", ta_cli_arguments_g[i].name);
printf(" ");
if (ta_cli_arguments_g[i].has_arg == REQUIRED_ARG) {
printf(" arg ");
} else if (ta_cli_arguments_g[i].has_arg == OPTIONAL_ARG) {
printf("[arg]");
} else {
printf(" ");
}
printf(" %s \n", ta_cli_arguments_g[i].desc);
}
}
52 changes: 52 additions & 0 deletions accelerator/message.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#ifndef ACCELERATOR_MESSAGE_H_
#define ACCELERATOR_MESSAGE_H_

#ifdef __cplusplus
extern "C" {
#endif

typedef enum ta_cli_arg_value_e {
HELP_CLI,

/** TA */
TA_HOST_CLI,
TA_PORT_CLI,
TA_THREAD_COUNT_CLI,
TA_VERSION_CLI,

/** IRI */
IRI_HOST_CLI,
IRI_PORT_CLI,

/** REDIS */
REDIS_HOST_CLI,
REDIS_PORT_CLI,

/** CONFIG */
MILESTONE_DEPTH_CLI,
MWM_CLI,
SEED_CLI,
} ta_cli_arg_value_t;

typedef enum ta_cli_arg_requirement_e {
NO_ARG,
REQUIRED_ARG,
OPTIONAL_ARG
} ta_cli_arg_requirement_t;

static struct ta_cli_argument_s {
char* name;
int val;
char* desc;
ta_cli_arg_requirement_t has_arg;
} ta_cli_arguments_g[] = {
{"ta-help", HELP_CLI, "Show tangle-accelerator usage.", NO_ARG}};

static const int cli_cmd_num =
sizeof(ta_cli_arguments_g) / sizeof(struct ta_cli_argument_s);
void ta_usage();
#ifdef __cplusplus
}
#endif

#endif // ACCELERATOR_MESSAGE_H_

0 comments on commit 5270af8

Please sign in to comment.