cli_helpers.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #pragma once
  2. #include <cli/cli.h>
  3. #include "../types/plugin_state.h"
  4. #define TOTP_CLI_COMMAND_NAME "totp"
  5. #define DOCOPT_ARGUMENT(arg) "<" arg ">"
  6. #define DOCOPT_MULTIPLE(arg) arg "..."
  7. #define DOCOPT_OPTIONAL(param) "[" param "]"
  8. #define DOCOPT_REQUIRED(param) "(" param ")"
  9. #define DOCOPT_OPTION(option, value) option " " value
  10. #define DOCOPT_SWITCH(option) option
  11. #define DOCOPT_OPTIONS "[options]"
  12. #define DOCOPT_DEFAULT(val) "[default: " val "]"
  13. #define TOTP_CLI_PRINTF(format, ...) \
  14. do { \
  15. _Pragma(STRINGIFY(GCC diagnostic push)) \
  16. _Pragma(STRINGIFY(GCC diagnostic ignored "-Wdouble-promotion")) \
  17. printf(format, ##__VA_ARGS__); \
  18. _Pragma(STRINGIFY(GCC diagnostic pop)) \
  19. } while(false)
  20. #define TOTP_CLI_DELETE_LAST_LINE() \
  21. TOTP_CLI_PRINTF("\033[A\33[2K\r"); \
  22. fflush(stdout)
  23. #define TOTP_CLI_DELETE_CURRENT_LINE() \
  24. TOTP_CLI_PRINTF("\33[2K\r"); \
  25. fflush(stdout)
  26. #define TOTP_CLI_DELETE_LAST_CHAR() \
  27. TOTP_CLI_PRINTF("\b \b"); \
  28. fflush(stdout)
  29. #define TOTP_CLI_PRINT_INVALID_ARGUMENTS() \
  30. TOTP_CLI_PRINTF( \
  31. "Invalid command arguments. use \"help\" command to get list of available commands")
  32. #define TOTP_CLI_PRINT_ERROR_UPDATING_CONFIG_FILE() \
  33. TOTP_CLI_PRINTF("An error has occurred during updating config file\r\n")
  34. /**
  35. * @brief Checks whether user is authenticated and entered correct PIN.
  36. * If user is not authenticated it prompts user to enter correct PIN to authenticate.
  37. * @param plugin_state application state
  38. * @param cli reference to the firmware CLI subsystem
  39. * @return \c true if user is already authenticated or successfully authenticated; \c false otherwise
  40. */
  41. bool totp_cli_ensure_authenticated(const PluginState* plugin_state, Cli* cli);