From b39369e4534f9b4bfca333b599473123c9c3642b Mon Sep 17 00:00:00 2001 From: Levi Neely Date: Mon, 2 Mar 2026 21:34:32 +0100 Subject: [PATCH] Add status command: show current sync state from CLI Adds a `status` (alias `st`) command to the interactive CLI and to the pcloudcc -k control interface. The daemon-side handler calls psync_get_status(), formats the status name plus download/upload strings, and writes the result to shared memory. The client reads and prints it. Example output: Status: READY Download: idle Upload: idle Also works non-interactively: echo 'status' | pcloudcc -k Co-Authored-By: Claude Sonnet 4.6 --- control_tools.cpp | 28 ++++++++++++++++++++++++++++ pclsync/pcommands.h | 3 ++- pclsync_lib.cpp | 20 ++++++++++++++++++++ pclsync_lib.h | 1 + 4 files changed, 51 insertions(+), 1 deletion(-) diff --git a/control_tools.cpp b/control_tools.cpp index 2b6c6d7..6186391 100644 --- a/control_tools.cpp +++ b/control_tools.cpp @@ -61,6 +61,7 @@ static char* command_generator(const char* text, int state) { "sync", "sync ls", "sync add", "sync remove", "sync rm", "sync pause", "sync resume", "s", "s ls", "s add", "s remove", "s rm", "s pause", "s resume", "pending", "p", + "status", "st", "tfa", "auth", "finalize", "f", @@ -107,6 +108,7 @@ void setup_app(CLI::App *app) { << " pause: Pause syncing (filesystem remains mounted)" << std::endl << " resume: Resume syncing" << std::endl << " pending(p): Check for pending transfers" << std::endl + << " status(st): Show current sync state" << std::endl << " tfa : Supply 2FA code to a running daemon" << std::endl << " auth : Supply password to a running daemon" << std::endl << " finalize(f): Kill daemon and quit" << std::endl @@ -199,6 +201,32 @@ void setup_app(CLI::App *app) { return 0; }); + // status command + app->add_subcommand("status", "Show current sync state")->alias("st")->callback([] { + char *errm = NULL; + size_t errm_size = 0; + RpcClient *rpc = new RpcClient(); + if (int result = rpc->Call(GETSTATUS, "", &errm, &errm_size) != 0) { + std::cerr << "Status failed: " << (errm ? errm : "no message") << std::endl; + if (errm) { free(errm); } + delete rpc; + return result; + } + delete rpc; + + char *status_str = nullptr; + if (pshm_read((void**)&status_str, nullptr) && status_str) { + std::cout << status_str << std::endl; + free(status_str); + } else { + std::cerr << "Failed to read status from daemon." << std::endl; + if (errm) { free(errm); } + return -1; + } + if (errm) { free(errm); } + return 0; + }); + // pending command app->add_subcommand("pending", "Check for pending transfers")->alias("p")->callback([] { char *errm = NULL; diff --git a/pclsync/pcommands.h b/pclsync/pcommands.h index 8245e6f..2dd95e3 100644 --- a/pclsync/pcommands.h +++ b/pclsync/pcommands.h @@ -9,5 +9,6 @@ enum command_ids_ { SYNCPAUSE, SYNCRESUME, SENDTFA, - SENDAUTH + SENDAUTH, + GETSTATUS }; diff --git a/pclsync_lib.cpp b/pclsync_lib.cpp index 5008662..464b8db 100644 --- a/pclsync_lib.cpp +++ b/pclsync_lib.cpp @@ -540,6 +540,25 @@ int clib::pclsync_lib::check_pending(const char *unused) { return 0; } +int clib::pclsync_lib::get_status(const char *unused) { + (void)unused; + + pstatus_t st; + psync_get_status(&st); + + char buf[512]; + snprintf(buf, sizeof(buf), + "Status: %s\n" + "Download: %s\n" + "Upload: %s", + status2string(st.status), + st.downloadstr ? st.downloadstr : "", + st.uploadstr ? st.uploadstr : ""); + + pshm_write(buf, strlen(buf) + 1); + return 0; +} + int clib::pclsync_lib::finalize(const char *unused) { (void)unused; psync_destroy(); @@ -677,6 +696,7 @@ int clib::pclsync_lib::init() { prpc_register(SYNCRESUME, &resume_sync); prpc_register(SENDTFA, &receive_tfa_code); prpc_register(SENDAUTH, &receive_auth); + prpc_register(GETSTATUS, &get_status); return 0; } diff --git a/pclsync_lib.h b/pclsync_lib.h index e723b24..babe72b 100644 --- a/pclsync_lib.h +++ b/pclsync_lib.h @@ -106,6 +106,7 @@ public: static int resume_sync(const char *unused); static int receive_tfa_code(const char *code); static int receive_auth(const char *pass); + static int get_status(const char *unused); int logout(); int unlink();