Skip to content

Commit afe7e56

Browse files
authored
Refactoring (#184)
1 parent 446e0a1 commit afe7e56

8 files changed

+93
-6
lines changed

cli/cli.c

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
#include "commands/automation/automation.h"
1717
#include "commands/details/details.h"
1818

19+
struct TotpCliContext {
20+
PluginState* plugin_state;
21+
};
22+
1923
static void totp_cli_print_unknown_command(const FuriString* unknown_command) {
2024
TOTP_CLI_PRINTF_ERROR(
2125
"Command \"%s\" is unknown. Use \"" TOTP_CLI_COMMAND_HELP

cli/cli.h

+11-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,17 @@
33
#include <cli/cli.h>
44
#include "../types/plugin_state.h"
55

6-
typedef struct {
7-
PluginState* plugin_state;
8-
} TotpCliContext;
6+
typedef struct TotpCliContext TotpCliContext;
97

8+
/**
9+
* @brief Registers TOTP CLI handler
10+
* @param plugin_state application state
11+
* @return TOTP CLI context
12+
*/
1013
TotpCliContext* totp_cli_register_command_handler(PluginState* plugin_state);
14+
15+
/**
16+
* @brief Unregisters TOTP CLI handler
17+
* @param context application state
18+
*/
1119
void totp_cli_unregister_command_handler(TotpCliContext* context);

cli/cli_helpers.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,6 @@ void totp_cli_print_error_updating_config_file();
111111
void totp_cli_print_error_loading_token_info();
112112

113113
/**
114-
* @brief Prints message to let user knwo that command is processing now
114+
* @brief Prints message to let user know that command is processing now
115115
*/
116116
void totp_cli_print_processing();

cli/commands/add/add.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ static TotpIteratorUpdateTokenResult
5454

5555
// Reading token secret
5656
furi_string_reset(temp_str);
57-
TOTP_CLI_PRINTF("Enter token secret and confirm with [ENTER]\r\n");
57+
TOTP_CLI_PRINTF("Enter token secret and confirm with [ENTER]:\r\n");
5858
if(!totp_cli_read_line(context_t->cli, temp_str, mask_user_input)) {
5959
totp_cli_delete_last_line();
6060
furi_string_secure_free(temp_str);

cli/commands/update/update.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ static TotpIteratorUpdateTokenResult
8383
if(update_token_secret) {
8484
// Reading token secret
8585
furi_string_reset(temp_str);
86-
TOTP_CLI_PRINTF("Enter token secret and confirm with [ENTER]\r\n");
86+
TOTP_CLI_PRINTF("Enter token secret and confirm with [ENTER]:\r\n");
8787
bool token_secret_read = totp_cli_read_line(context_t->cli, temp_str, mask_user_input);
8888
totp_cli_delete_last_line();
8989
if(!token_secret_read) {

cli/common_command_arguments.h

+55
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,87 @@
1818
#define TOTP_CLI_COMMAND_ARG_SECRET_ENCODING_PREFIX "-e"
1919
#define TOTP_CLI_COMMAND_ARG_SECRET_ENCODING "encoding"
2020

21+
/**
22+
* @brief Prints information about unknown argument
23+
* @param arg
24+
*/
2125
void totp_cli_printf_unknown_argument(const FuriString* arg);
2226

27+
/**
28+
* @brief Prints information about missed required argument
29+
* @param arg
30+
*/
2331
void totp_cli_printf_missed_argument_value(char* arg);
2432

33+
/**
34+
* @brief Tries to read token hashing algo
35+
* @param token_info token info to set parsed algo to if successfully read and parsed
36+
* @param arg argument to parse
37+
* @param args rest of arguments
38+
* @param[out] parsed will be set to \c true if token hashing algo sucecssfully read and parsed; \c false otherwise
39+
* @return \c true if \c arg represents token hashing algo argument; \c false otherwise
40+
*/
2541
bool totp_cli_try_read_algo(TokenInfo* token_info, FuriString* arg, FuriString* args, bool* parsed);
2642

43+
/**
44+
* @brief Tries to read token digits count
45+
* @param token_info token info to set parsed digits count to if successfully read and parsed
46+
* @param arg argument to parse
47+
* @param args rest of arguments
48+
* @param[out] parsed will be set to \c true if token digits count sucecssfully read and parsed; \c false otherwise
49+
* @return \c true if \c arg represents token digits count argument; \c false otherwise
50+
*/
2751
bool totp_cli_try_read_digits(
2852
TokenInfo* token_info,
2953
const FuriString* arg,
3054
FuriString* args,
3155
bool* parsed);
3256

57+
/**
58+
* @brief Tries to read token duration
59+
* @param token_info token info to set parsed duration to if successfully read and parsed
60+
* @param arg argument to parse
61+
* @param args rest of arguments
62+
* @param[out] parsed will be set to \c true if token duration sucecssfully read and parsed; \c false otherwise
63+
* @return \c true if \c arg represents token duration argument; \c false otherwise
64+
*/
3365
bool totp_cli_try_read_duration(
3466
TokenInfo* token_info,
3567
const FuriString* arg,
3668
FuriString* args,
3769
bool* parsed);
3870

71+
/**
72+
* @brief Tries to read token automation features
73+
* @param token_info token info to set parsed automation features to if successfully read and parsed
74+
* @param arg argument to parse
75+
* @param args rest of arguments
76+
* @param[out] parsed will be set to \c true if token automation features sucecssfully read and parsed; \c false otherwise
77+
* @return \c true if \c arg represents token automation features argument; \c false otherwise
78+
*/
3979
bool totp_cli_try_read_automation_features(
4080
TokenInfo* token_info,
4181
FuriString* arg,
4282
FuriString* args,
4383
bool* parsed);
4484

85+
/**
86+
* @brief Tries to read unsecure flag
87+
* @param arg argument to parse
88+
* @param[out] parsed will be set to \c true if unsecure flag sucecssfully read and parsed; \c false otherwise
89+
* @param[out] unsecure_flag will be set to parsed unsecure flag state if read and parsed successfully
90+
* @return \c true if \c arg represents unsecure flag argument; \c false otherwise
91+
*/
4592
bool totp_cli_try_read_unsecure_flag(const FuriString* arg, bool* parsed, bool* unsecure_flag);
4693

94+
/**
95+
* @brief Tries to read plain token secret encoding
96+
* @param arg argument to parse
97+
* @param args rest of arguments
98+
* @param[out] parsed will be set to \c true if plain token secret encoding sucecssfully read and parsed; \c false otherwise
99+
* @param[out] secret_encoding will be set to parsed plain token secret encoding if read and parsed successfully
100+
* @return \c true if \c arg represents plain token secret encoding argument; \c false otherwise
101+
*/
47102
bool totp_cli_try_read_plain_token_secret_encoding(
48103
FuriString* arg,
49104
FuriString* args,

ui/canvas_extensions.h

+9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44
#include <gui/gui.h>
55
#include <font_info.h>
66

7+
/**
8+
* @brief Draw string using given font
9+
* @param canvas canvas to draw string at
10+
* @param x horizontal position
11+
* @param y vertical position
12+
* @param text string to draw
13+
* @param text_length string length
14+
* @param font font to be used to draw string
15+
*/
716
void canvas_draw_str_ex(
817
Canvas* canvas,
918
uint8_t x,

ui/common_dialogs.h

+11
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,16 @@
33
#include <dialogs/dialogs.h>
44
#include "../types/plugin_state.h"
55

6+
/**
7+
* @brief Shows standard dialog about the fact that error occurred when loading config file
8+
* @param plugin_state application state
9+
* @return dialog button which user pressed to close the dialog
10+
*/
611
DialogMessageButton totp_dialogs_config_loading_error(PluginState* plugin_state);
12+
13+
/**
14+
* @brief Shows standard dialog about the fact that error occurred when updating config file
15+
* @param plugin_state application state
16+
* @return dialog button which user pressed to close the dialog
17+
*/
718
DialogMessageButton totp_dialogs_config_updating_error(PluginState* plugin_state);

0 commit comments

Comments
 (0)