upython_cli.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include <storage/storage.h>
  2. #include "upython.h"
  3. void upython_cli(Cli* cli, FuriString* args, void* ctx) {
  4. UNUSED(ctx);
  5. if(action != ActionNone) {
  6. printf("%s is busy!\n", TAG);
  7. return;
  8. }
  9. if(furi_string_empty(args)) {
  10. action = ActionRepl;
  11. upython_repl_execute(cli);
  12. action = ActionNone;
  13. } else {
  14. furi_string_set(file_path, args);
  15. action = ActionExec;
  16. }
  17. }
  18. void upython_cli_register(void* args) {
  19. if(args != NULL) {
  20. file_path = furi_string_alloc_set_str(args);
  21. action = ActionExec;
  22. return;
  23. } else {
  24. file_path = furi_string_alloc();
  25. upython_reset_file_path();
  26. action = ActionNone;
  27. }
  28. Cli* cli = furi_record_open(RECORD_CLI);
  29. cli_add_command(cli, CLI, CliCommandFlagParallelSafe, upython_cli, NULL);
  30. furi_record_close(RECORD_CLI);
  31. }
  32. void upython_cli_unregister(void* args) {
  33. furi_string_free(file_path);
  34. if(args != NULL) {
  35. return;
  36. }
  37. Cli* cli = furi_record_open(RECORD_CLI);
  38. cli_delete_command(cli, CLI);
  39. furi_record_close(RECORD_CLI);
  40. }