Debian Codegraph @

codelite-cli/csListCommandHandler.cpp

raw
1 #include "csListCommandHandler.h"
2 #include "JSON.h"
3 #include <file_logger.h>
4 #include <iostream>
5 #include <wx/dir.h>
6 #include "csManager.h"
7
8 csListCommandHandler::csListCommandHandler(csManager* manager)
9 : csCommandHandlerBase(manager)
10 {
11 }
12
13 csListCommandHandler::~csListCommandHandler() {}
14
15 void csListCommandHandler::DoProcessCommand(const JSONItem& options)
16 {
17 clDEBUG() << "Processing list command...";
18 CHECK_STR_PARAM("path", m_folder);
19
20 // Prepare the output
21 wxDir dir(m_folder);
22 wxString filename;
23 bool cont = dir.GetFirst(&filename);
24 JSON json(cJSON_Array);
25 JSONItem arr = json.toElement();
26 while(cont) {
27 wxFileName fn(m_folder, filename);
28 JSONItem entry = JSONItem::createObject();
29 wxString fullpath = fn.GetFullPath();
30 entry.addProperty("path", fn.GetFullPath());
31 entry.addProperty("type", wxFileName::DirExists(fullpath) ? "dir" : "file");
32 arr.arrayAppend(entry);
33 cont = dir.GetNext(&filename);
34 }
35 char* result = arr.FormatRawString(m_manager->GetConfig().IsPrettyJSON());
36 clDEBUG() << result;
37 std::cout << result << std::endl;
38 free(result);
39 }