change:标准化命令和添加命令说明。
This commit is contained in:
parent
eea5eee933
commit
f6e7596367
@ -1,6 +1,6 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(transm VERSION 1.4.0 LANGUAGES CXX)
|
||||
project(transm VERSION 1.4.1 LANGUAGES CXX)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
|
@ -50,6 +50,78 @@ CClient::~CClient()
|
||||
}
|
||||
}
|
||||
|
||||
void CClient::print_help(bool detail)
|
||||
{
|
||||
TLOGI("version: {}", VERSION_NUM);
|
||||
TLOGI("opensource: {}", VERSION_URL);
|
||||
TLOGW("SupportCmd ==>");
|
||||
|
||||
if (!detail) {
|
||||
TLOGI("Get|Who|Where|Ls|Sub|Fetch|Up|Down|UpTask|DownTask");
|
||||
TLOGI("You can use 'h' to show cmd's detail.");
|
||||
TLOGI("You can use 'end' or 'ctrl-c' to exit.");
|
||||
return;
|
||||
}
|
||||
|
||||
constexpr char* sp = "==================================================";
|
||||
TLOGI("{}", sp);
|
||||
TLOGW("#Get#");
|
||||
TLOGI(" des: Get all clients on server.");
|
||||
TLOGI(" cmd: Get get g G");
|
||||
TLOGI(" arg: NULL");
|
||||
TLOGI("{}", sp);
|
||||
TLOGW("#Who#");
|
||||
TLOGI(" des: Show current client's ID.");
|
||||
TLOGI(" cmd: Who who");
|
||||
TLOGI(" arg: NULL");
|
||||
TLOGI("{}", sp);
|
||||
TLOGW("#Where#");
|
||||
TLOGI(" des: Show current client's work dir.");
|
||||
TLOGI(" cmd: Where where wh");
|
||||
TLOGI(" arg: NULL");
|
||||
TLOGI("{}", sp);
|
||||
TLOGW("#Ls#");
|
||||
TLOGI(" des: List one client's all files and folders.");
|
||||
TLOGI(" cmd: Ls ls");
|
||||
TLOGI(" arg: @id @dir");
|
||||
TLOGI("{}", sp);
|
||||
TLOGW("#Sub#");
|
||||
TLOGI(" des: Submit local file's list on the server.");
|
||||
TLOGI(" cmd: Sub sub");
|
||||
TLOGI(" arg: @files(Separated by | if multi)");
|
||||
TLOGI("{}", sp);
|
||||
TLOGW("#Fetch#");
|
||||
TLOGI(" des: Fetch one client's submited files.");
|
||||
TLOGI(" cmd: Fetch fetch");
|
||||
TLOGI(" arg: @id @savedir");
|
||||
TLOGI("{}", sp);
|
||||
TLOGW("#Clear#");
|
||||
TLOGI(" des: clear submited list.");
|
||||
TLOGI(" cmd: Clear clear c C");
|
||||
TLOGI(" arg: NULL");
|
||||
TLOGI("{}", sp);
|
||||
TLOGW("#Up#");
|
||||
TLOGI(" des: Upload local files to one client directly.");
|
||||
TLOGI(" cmd: Up up");
|
||||
TLOGI(" arg: @id @files(Sep by | if multi) @savedir");
|
||||
TLOGI("{}", sp);
|
||||
TLOGW("#Down#");
|
||||
TLOGI(" des: Down one client's files directly.");
|
||||
TLOGI(" cmd: Down down");
|
||||
TLOGI(" arg: @id @files(Sep by | if multi) @savedir(opt)");
|
||||
TLOGI("{}", sp);
|
||||
TLOGW("#UpTask#");
|
||||
TLOGI(" des: Down one client's files directly.");
|
||||
TLOGI(" cmd: UpTask uptask ut");
|
||||
TLOGI(" arg: @id @taskfile(UTF-8)");
|
||||
TLOGI("{}", sp);
|
||||
TLOGW("#DownTask#");
|
||||
TLOGI(" des: Down one client's files directly.");
|
||||
TLOGI(" cmd: DownTask downtask dt");
|
||||
TLOGI(" arg: @id @taskfile(UTF-8)");
|
||||
TLOGI("{}", sp);
|
||||
}
|
||||
|
||||
void CClient::run(const std::string& ip, const std::string& port, const std::string& config_dir)
|
||||
{
|
||||
fs::path fp(config_dir);
|
||||
@ -82,13 +154,9 @@ void CClient::run(const std::string& ip, const std::string& port, const std::str
|
||||
|
||||
get_id();
|
||||
if (ip == "127.0.0.1") {
|
||||
get_task_list();
|
||||
get_clients();
|
||||
}
|
||||
|
||||
TLOGI("version: {}", VERSION_NUM);
|
||||
TLOGI("opensource: {}", VERSION_URL);
|
||||
TLOGW("SupportCmd ==>");
|
||||
TLOGW("Get|Up|Down|Cancel|Update|Who|Where|Ls|Req");
|
||||
print_help(false);
|
||||
fc_append('|');
|
||||
|
||||
while (1) {
|
||||
@ -104,6 +172,12 @@ void CClient::run(const std::string& ip, const std::string& port, const std::str
|
||||
fc_free(readline);
|
||||
std::cout << "" << std::endl;
|
||||
cmd_input = ofen::COfStr::trim(cmd_input);
|
||||
|
||||
if (cmd_input == "help" || cmd_input == "h") {
|
||||
print_help(true);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (cmd_input == "end" || cmd_input == "End") {
|
||||
th_run_ = false;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
@ -119,11 +193,11 @@ void CClient::run(const std::string& ip, const std::string& port, const std::str
|
||||
continue;
|
||||
}
|
||||
if (cmd_input == "Get" || cmd_input == "get" || cmd_input == "g" || cmd_input == "G") {
|
||||
get_task_list();
|
||||
get_clients();
|
||||
continue;
|
||||
}
|
||||
if (cmd_input == "Cancel" || cmd_input == "cancel" || cmd_input == "c" || cmd_input == "C") {
|
||||
cancel_task();
|
||||
if (cmd_input == "Clear" || cmd_input == "clear" || cmd_input == "c" || cmd_input == "C") {
|
||||
cmd_clear_submited();
|
||||
continue;
|
||||
}
|
||||
auto vec = COfStr::split(cmd_input, " ");
|
||||
@ -135,28 +209,28 @@ void CClient::run(const std::string& ip, const std::string& port, const std::str
|
||||
std::string scmd = param.substr(0, param.find_first_of(" "));
|
||||
param.erase(0, param.find_first_of(" ") + 1);
|
||||
|
||||
if (scmd == "Update" || scmd == "update") {
|
||||
request_update_list(param);
|
||||
continue;
|
||||
}
|
||||
if (scmd == "Send" || scmd == "send") {
|
||||
send_files(param);
|
||||
continue;
|
||||
}
|
||||
if (scmd == "Down" || scmd == "down") {
|
||||
down_task(param);
|
||||
if (scmd == "UpTask" || scmd == "uptask" || scmd == "ut") {
|
||||
cmd_uptask(param);
|
||||
continue;
|
||||
}
|
||||
if (scmd == "Up" || scmd == "up") {
|
||||
up_task(param);
|
||||
cmd_upload_files(param);
|
||||
continue;
|
||||
}
|
||||
if (scmd == "Fetch" || scmd == "fetch") {
|
||||
cmd_fetch_files(param);
|
||||
continue;
|
||||
}
|
||||
if (scmd == "Sub" || scmd == "sub") {
|
||||
cmd_sub_list(param);
|
||||
continue;
|
||||
}
|
||||
if (scmd == "Ls" || scmd == "ls") {
|
||||
require_dir_files(param);
|
||||
cmd_ls(param);
|
||||
continue;
|
||||
}
|
||||
if (scmd == "Req" || scmd == "req") {
|
||||
down_req_list(param);
|
||||
if (scmd == "Down" || scmd == "down") {
|
||||
cmd_down_list(param);
|
||||
continue;
|
||||
}
|
||||
TLOGE("No matched cmd, May be param size incorrect.");
|
||||
@ -166,14 +240,14 @@ void CClient::run(const std::string& ip, const std::string& port, const std::str
|
||||
TLOGI("{} exit.", __FUNCTION__);
|
||||
}
|
||||
|
||||
bool CClient::get_task_list()
|
||||
bool CClient::get_clients()
|
||||
{
|
||||
std::shared_ptr<CFrameBuffer> buf = std::make_shared<CFrameBuffer>();
|
||||
buf->type_ = TYPE_GET_LIST;
|
||||
return send_frame(buf.get());
|
||||
}
|
||||
|
||||
bool CClient::down_task(const std::string& param)
|
||||
bool CClient::cmd_fetch_files(const std::string& param)
|
||||
{
|
||||
if (downloading_) {
|
||||
TLOGW("Have Task Downloading, Please wait.....");
|
||||
@ -218,7 +292,7 @@ bool CClient::down_task(const std::string& param)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CClient::up_task(const std::string& param)
|
||||
bool CClient::cmd_sub_list(const std::string& param)
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
@ -270,7 +344,7 @@ bool CClient::up_task(const std::string& param)
|
||||
return send_frame(buf.get());
|
||||
}
|
||||
|
||||
bool CClient::cancel_task()
|
||||
bool CClient::cmd_clear_submited()
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
@ -286,7 +360,7 @@ bool CClient::cancel_task()
|
||||
return send_frame(buf.get());
|
||||
}
|
||||
|
||||
bool CClient::send_files(const std::string& param)
|
||||
bool CClient::cmd_upload_files(const std::string& param)
|
||||
{
|
||||
auto tvec = COfStr::split(param, " ");
|
||||
if (tvec.size() < 3) {
|
||||
@ -470,7 +544,7 @@ void CClient::report_trans_ret(TransState state, const std::string& key)
|
||||
|
||||
功能为,请求某个客户端,更新我所列出的文件,右侧是远端需要存储的目录(必须存在,不存在则不理会)
|
||||
*/
|
||||
bool CClient::request_update_list(const std::string& param)
|
||||
bool CClient::cmd_uptask(const std::string& param)
|
||||
{
|
||||
auto tvec = COfStr::split(param, " ");
|
||||
if (tvec.size() < 2) {
|
||||
@ -665,7 +739,7 @@ bool CClient::get_dir_files(const std::string& dir, std::string& out, std::strin
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CClient::require_dir_files(const std::string& param)
|
||||
bool CClient::cmd_ls(const std::string& param)
|
||||
{
|
||||
auto tvec = COfStr::split(param, " ");
|
||||
if (tvec.size() < 2) {
|
||||
@ -695,7 +769,7 @@ bool CClient::require_dir_files(const std::string& param)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CClient::down_req_list(const std::string& param)
|
||||
bool CClient::cmd_down_list(const std::string& param)
|
||||
{
|
||||
auto tvec = COfStr::split(param, " ");
|
||||
if (tvec.size() < 2) {
|
||||
|
@ -48,19 +48,19 @@ public:
|
||||
void run(const std::string& ip, const std::string& port, const std::string& config_dir);
|
||||
|
||||
public:
|
||||
bool get_task_list();
|
||||
bool down_task(const std::string& param);
|
||||
bool up_task(const std::string& param);
|
||||
bool cancel_task();
|
||||
bool send_files(const std::string& param);
|
||||
bool get_clients();
|
||||
bool cmd_fetch_files(const std::string& param);
|
||||
bool cmd_sub_list(const std::string& param);
|
||||
bool cmd_clear_submited();
|
||||
bool cmd_upload_files(const std::string& param);
|
||||
bool down_one_file(int remote_id, const std::string& file, const std::string& local_dir = "");
|
||||
void report_trans_ret(TransState state, const std::string& key = "");
|
||||
bool request_update_list(const std::string& param);
|
||||
bool cmd_uptask(const std::string& param);
|
||||
bool check_update_list(const std::string& content, std::map<std::string, std::string>& files);
|
||||
bool down_update_file(const std::map<std::string, std::string>& files);
|
||||
bool get_dir_files(const std::string& dir, std::string& out, std::string& error);
|
||||
bool require_dir_files(const std::string& param);
|
||||
bool down_req_list(const std::string& param);
|
||||
bool cmd_ls(const std::string& param);
|
||||
bool cmd_down_list(const std::string& param);
|
||||
|
||||
private:
|
||||
bool send_frame(CFrameBuffer* buf);
|
||||
@ -69,6 +69,7 @@ private:
|
||||
bool save_uuid();
|
||||
std::string read_uuid();
|
||||
void get_id();
|
||||
void print_help(bool detail);
|
||||
|
||||
private:
|
||||
void handle_frame(CFrameBuffer* buf);
|
||||
|
@ -106,7 +106,7 @@ inline std::string now_str()
|
||||
auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()) % 1000;
|
||||
|
||||
std::ostringstream timestamp;
|
||||
timestamp << std::put_time(std::localtime(&time_t_now), "[%Y-%m-%d %H:%M:%S") << "." << std::setfill('0')
|
||||
timestamp << std::put_time(std::localtime(&time_t_now), "[%m-%d %H:%M:%S") << "." << std::setfill('0')
|
||||
<< std::setw(3) << milliseconds.count() << "] ";
|
||||
|
||||
return timestamp.str();
|
||||
|
Loading…
x
Reference in New Issue
Block a user