cli_helpers.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. bool totp_cli_ensure_authenticated(const PluginState* plugin_state, Cli* cli);