Skip to content

Commit 6ee9528

Browse files
authored
Implemented #102 (#104)
1 parent 297fffe commit 6ee9528

File tree

3 files changed

+11
-45
lines changed

3 files changed

+11
-45
lines changed

totp/cli/commands/help/help.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ void totp_cli_command_help_handle() {
5555
TOTP_CLI_PRINTF("Arguments:\r\n");
5656
totp_cli_command_add_docopt_arguments();
5757
totp_cli_command_delete_docopt_arguments();
58+
totp_cli_command_move_docopt_arguments();
5859
totp_cli_command_timezone_docopt_arguments();
5960
totp_cli_command_notification_docopt_arguments();
6061
totp_cli_command_automation_docopt_arguments();
@@ -63,5 +64,4 @@ void totp_cli_command_help_handle() {
6364
totp_cli_command_add_docopt_options();
6465
totp_cli_command_update_docopt_options();
6566
totp_cli_command_delete_docopt_options();
66-
totp_cli_command_move_docopt_options();
6767
}

totp/cli/commands/move/move.c

+9-43
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
#include "../../../ui/scene_director.h"
1010
#include "../../common_command_arguments.h"
1111

12-
#define TOTP_CLI_COMMAND_MOVE_ARG_NEW_INDEX "index"
13-
#define TOTP_CLI_COMMAND_MOVE_ARG_NEW_INDEX_PREFIX "-i"
12+
#define TOTP_CLI_COMMAND_MOVE_ARG_NEW_INDEX "new_index"
1413

1514
void totp_cli_command_move_docopt_commands() {
1615
TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_MOVE ", " TOTP_CLI_COMMAND_MOVE_ALT
@@ -20,16 +19,13 @@ void totp_cli_command_move_docopt_commands() {
2019
void totp_cli_command_move_docopt_usage() {
2120
TOTP_CLI_PRINTF(
2221
" " TOTP_CLI_COMMAND_NAME
23-
" " DOCOPT_REQUIRED(TOTP_CLI_COMMAND_MOVE " | " TOTP_CLI_COMMAND_MOVE_ALT) " " DOCOPT_ARGUMENT(TOTP_CLI_COMMAND_ARG_INDEX) " " DOCOPT_OPTIONAL(
24-
DOCOPT_OPTION(
25-
TOTP_CLI_COMMAND_MOVE_ARG_NEW_INDEX_PREFIX,
26-
DOCOPT_ARGUMENT(TOTP_CLI_COMMAND_MOVE_ARG_NEW_INDEX))) "\r\n");
22+
" " DOCOPT_REQUIRED(TOTP_CLI_COMMAND_MOVE " | " TOTP_CLI_COMMAND_MOVE_ALT) " " DOCOPT_ARGUMENT(
23+
TOTP_CLI_COMMAND_ARG_INDEX) " " DOCOPT_ARGUMENT(TOTP_CLI_COMMAND_MOVE_ARG_NEW_INDEX) "\r\n");
2724
}
2825

29-
void totp_cli_command_move_docopt_options() {
30-
TOTP_CLI_PRINTF(" " DOCOPT_OPTION(
31-
TOTP_CLI_COMMAND_MOVE_ARG_NEW_INDEX_PREFIX,
32-
DOCOPT_ARGUMENT(TOTP_CLI_COMMAND_MOVE_ARG_NEW_INDEX)) " New token index\r\n");
26+
void totp_cli_command_move_docopt_arguments() {
27+
TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_MOVE_ARG_NEW_INDEX
28+
" New token index in the list\r\n");
3329
}
3430

3531
void totp_cli_command_move_handle(PluginState* plugin_state, FuriString* args, Cli* cli) {
@@ -44,39 +40,11 @@ void totp_cli_command_move_handle(PluginState* plugin_state, FuriString* args, C
4440
return;
4541
}
4642

47-
FuriString* temp_str = furi_string_alloc();
48-
4943
int new_token_index = 0;
5044

51-
while(args_read_string_and_trim(args, temp_str)) {
52-
bool parsed = false;
53-
if(furi_string_cmpi_str(temp_str, TOTP_CLI_COMMAND_MOVE_ARG_NEW_INDEX_PREFIX) == 0) {
54-
if(!args_read_int_and_trim(args, &new_token_index)) {
55-
TOTP_CLI_PRINTF_ERROR(
56-
"Missed value for argument \"" TOTP_CLI_COMMAND_MOVE_ARG_NEW_INDEX_PREFIX
57-
"\"\r\n");
58-
} else if(new_token_index < 1 || new_token_index > plugin_state->tokens_count) {
59-
TOTP_CLI_PRINTF_ERROR(
60-
"\"%" PRId16
61-
"\" is incorrect value for argument \"" TOTP_CLI_COMMAND_MOVE_ARG_NEW_INDEX_PREFIX
62-
"\"\r\n",
63-
new_token_index);
64-
} else {
65-
parsed = true;
66-
}
67-
} else {
68-
TOTP_CLI_PRINTF_ERROR("Unknown argument \"%s\"\r\n", furi_string_get_cstr(temp_str));
69-
}
70-
71-
if(!parsed) {
72-
TOTP_CLI_PRINT_INVALID_ARGUMENTS();
73-
furi_string_free(temp_str);
74-
return;
75-
}
76-
}
77-
78-
if(!totp_cli_ensure_authenticated(plugin_state, cli)) {
79-
furi_string_free(temp_str);
45+
if(!args_read_int_and_trim(args, &new_token_index) || new_token_index < 1 ||
46+
new_token_index > plugin_state->tokens_count) {
47+
TOTP_CLI_PRINT_INVALID_ARGUMENTS();
8048
return;
8149
}
8250

@@ -113,6 +81,4 @@ void totp_cli_command_move_handle(PluginState* plugin_state, FuriString* args, C
11381
if(activate_generate_token_scene) {
11482
totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken, NULL);
11583
}
116-
117-
furi_string_free(temp_str);
11884
}

totp/cli/commands/move/move.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
void totp_cli_command_move_handle(PluginState* plugin_state, FuriString* args, Cli* cli);
1010
void totp_cli_command_move_docopt_commands();
1111
void totp_cli_command_move_docopt_usage();
12-
void totp_cli_command_move_docopt_options();
12+
void totp_cli_command_move_docopt_arguments();

0 commit comments

Comments
 (0)