cli_helpers.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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_OPTIONAL(param) "[" param "]"
  7. #define DOCOPT_REQUIRED(param) "(" param ")"
  8. #define DOCOPT_OPTION(option, value) option " " value
  9. #define DOCOPT_SWITCH(option) option
  10. #define DOCOPT_OPTIONS "[options]"
  11. #define DOCOPT_DEFAULT(val) "[default: " val "]"
  12. #define TOTP_CLI_PRINTF(format, ...) \
  13. do { \
  14. _Pragma(STRINGIFY(GCC diagnostic push)) \
  15. _Pragma(STRINGIFY(GCC diagnostic ignored "-Wdouble-promotion")) \
  16. printf(format, ##__VA_ARGS__); \
  17. _Pragma(STRINGIFY(GCC diagnostic pop)) \
  18. } while(false)
  19. #define TOTP_CLI_DELETE_LAST_LINE() \
  20. TOTP_CLI_PRINTF("\033[A\33[2K\r"); \
  21. fflush(stdout)
  22. #define TOTP_CLI_DELETE_CURRENT_LINE() \
  23. TOTP_CLI_PRINTF("\33[2K\r"); \
  24. fflush(stdout)
  25. #define TOTP_CLI_DELETE_LAST_CHAR() \
  26. TOTP_CLI_PRINTF("\b \b"); \
  27. fflush(stdout)
  28. #define TOTP_CLI_PRINT_INVALID_ARGUMENTS() \
  29. TOTP_CLI_PRINTF( \
  30. "Invalid command arguments. use \"help\" command to get list of available commands")
  31. /**
  32. * @brief Checks whether user is authenticated and entered correct PIN.
  33. * If user is not authenticated it prompts user to enter correct PIN to authenticate.
  34. * @param plugin_state application state
  35. * @param cli reference to the firmware CLI subsystem
  36. * @return \c true if user is already authenticated or successfully authenticated; \c false otherwise
  37. */
  38. bool totp_cli_ensure_authenticated(const PluginState* plugin_state, Cli* cli);