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 <noreply@anthropic.com>
This commit is contained in:
parent
e0c3be4771
commit
b39369e453
|
|
@ -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 <code>: Supply 2FA code to a running daemon" << std::endl
|
||||
<< " auth <password>: 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;
|
||||
|
|
|
|||
|
|
@ -9,5 +9,6 @@ enum command_ids_ {
|
|||
SYNCPAUSE,
|
||||
SYNCRESUME,
|
||||
SENDTFA,
|
||||
SENDAUTH
|
||||
SENDAUTH,
|
||||
GETSTATUS
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Reference in New Issue