106f6ba60Sopenharmony_ci/* 206f6ba60Sopenharmony_ci * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved. 306f6ba60Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 406f6ba60Sopenharmony_ci * you may not use this file except in compliance with the License. 506f6ba60Sopenharmony_ci * You may obtain a copy of the License at 606f6ba60Sopenharmony_ci * 706f6ba60Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 806f6ba60Sopenharmony_ci * 906f6ba60Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1006f6ba60Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1106f6ba60Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1206f6ba60Sopenharmony_ci * See the License for the specific language governing permissions and 1306f6ba60Sopenharmony_ci * limitations under the License. 1406f6ba60Sopenharmony_ci */ 1506f6ba60Sopenharmony_ci 1606f6ba60Sopenharmony_ci#include <iostream> 1706f6ba60Sopenharmony_ci 1806f6ba60Sopenharmony_ci#include "command_helper.h" 1906f6ba60Sopenharmony_ci 2006f6ba60Sopenharmony_ciint CommandHelper::Start(int* argc, char*** argv, const std::string& help) 2106f6ba60Sopenharmony_ci{ 2206f6ba60Sopenharmony_ci if ((*argc) == 1) { 2306f6ba60Sopenharmony_ci // no argument specified, we speculate the user may do not know the command usage. 2406f6ba60Sopenharmony_ci // Hence print the usage help and continue 2506f6ba60Sopenharmony_ci std::cout << tipHelp_ << std::endl; 2606f6ba60Sopenharmony_ci return 0; 2706f6ba60Sopenharmony_ci } 2806f6ba60Sopenharmony_ci if (help.compare(SUPPORTED_ARGS[ARG_NONG]) == 0) { 2906f6ba60Sopenharmony_ci // user does not issue help 3006f6ba60Sopenharmony_ci bool printTip {false}; 3106f6ba60Sopenharmony_ci for (int count = 1; count < (*argc); ++count) { 3206f6ba60Sopenharmony_ci if ((*argv)[count] and strlen((*argv)[count]) != 0) { 3306f6ba60Sopenharmony_ci // undefined commandline argument specified, we speculate the user may do 3406f6ba60Sopenharmony_ci // not know the command usage. Hence print the usage help and continue 3506f6ba60Sopenharmony_ci printTip = true; 3606f6ba60Sopenharmony_ci std::cout << "CommandHelper WARN: argument " << (*argv)[count] 3706f6ba60Sopenharmony_ci << " specified but unused" << std::endl; 3806f6ba60Sopenharmony_ci } 3906f6ba60Sopenharmony_ci } 4006f6ba60Sopenharmony_ci if (printTip) { 4106f6ba60Sopenharmony_ci std::cout << tipHelp_ << std::endl; 4206f6ba60Sopenharmony_ci } 4306f6ba60Sopenharmony_ci return 0; 4406f6ba60Sopenharmony_ci } 4506f6ba60Sopenharmony_ci DoHelp(help); 4606f6ba60Sopenharmony_ci return -1; 4706f6ba60Sopenharmony_ci} 4806f6ba60Sopenharmony_ci 4906f6ba60Sopenharmony_civoid CommandHelper::DoHelp(const std::string& help) 5006f6ba60Sopenharmony_ci{ 5106f6ba60Sopenharmony_ci if (help.compare(SUPPORTED_ARGS[ARG_HELP]) == 0) { 5206f6ba60Sopenharmony_ci std::cout << helpHelp_ << std::endl; 5306f6ba60Sopenharmony_ci } else if (help.compare(SUPPORTED_ARGS[ARG_OUTPUT_FILE]) == 0) { 5406f6ba60Sopenharmony_ci std::cout << outputFileHelp_ << std::endl; 5506f6ba60Sopenharmony_ci } else if (help.compare(SUPPORTED_ARGS[ARG_EXCLUDE_TRACER]) == 0) { 5606f6ba60Sopenharmony_ci std::cout << excludeTracerHelp_ << std::endl; 5706f6ba60Sopenharmony_ci } else if (help.compare(SUPPORTED_ARGS[ARG_MAX_STACK_DEPTH]) == 0) { 5806f6ba60Sopenharmony_ci std::cout << maxStackDepthHelp_ << std::endl; 5906f6ba60Sopenharmony_ci } else if (help.compare(SUPPORTED_ARGS[ARG_DURATION]) == 0) { 6006f6ba60Sopenharmony_ci std::cout << durationHelp_ << std::endl; 6106f6ba60Sopenharmony_ci } else if (help.compare(SUPPORTED_ARGS[ARG_EVENTS]) == 0) { 6206f6ba60Sopenharmony_ci std::cout << eventsHelp_ << std::endl; 6306f6ba60Sopenharmony_ci } else if (help.compare(SUPPORTED_ARGS[ARG_PIDS]) == 0) { 6406f6ba60Sopenharmony_ci std::cout << pidsHelp_ << std::endl; 6506f6ba60Sopenharmony_ci } else if (help.compare(SUPPORTED_ARGS[ARG_DUMP_EVENTS]) == 0) { 6606f6ba60Sopenharmony_ci std::cout << dumpEventsHelp_ << std::endl; 6706f6ba60Sopenharmony_ci } else if (help.compare(SUPPORTED_ARGS[ARG_UNWIND_STACK]) == 0) { 6806f6ba60Sopenharmony_ci std::cout << unwindStackHelp_ << std::endl; 6906f6ba60Sopenharmony_ci } else if (help.compare(SUPPORTED_ARGS[ARG_BPF_LOG_LEVEL]) == 0) { 7006f6ba60Sopenharmony_ci std::cout << bpfLogLevelHelp_ << std::endl; 7106f6ba60Sopenharmony_ci } else if (help.compare(SUPPORTED_ARGS[ARG_BPF_LOG_FILE]) == 0) { 7206f6ba60Sopenharmony_ci std::cout << bpfLogFileHelp_ << std::endl; 7306f6ba60Sopenharmony_ci } else if (help.compare(SUPPORTED_ARGS[ARG_LIBBPF_LOG_LEVEL]) == 0) { 7406f6ba60Sopenharmony_ci std::cout << libbpfLogLevelHelp_ << std::endl; 7506f6ba60Sopenharmony_ci } else if (help.compare(SUPPORTED_ARGS[ARG_LIBBPF_LOG_FILE]) == 0) { 7606f6ba60Sopenharmony_ci std::cout << libbpfFileHelp_ << std::endl; 7706f6ba60Sopenharmony_ci } else if (help.compare(SUPPORTED_ARGS[ARG_SERVER_START]) == 0) { 7806f6ba60Sopenharmony_ci std::cout << serverStartHelp_ << std::endl; 7906f6ba60Sopenharmony_ci } else if (help.compare(SUPPORTED_ARGS[ARG_SERVER_STOP]) == 0) { 8006f6ba60Sopenharmony_ci std::cout << serverStopHelp_ << std::endl; 8106f6ba60Sopenharmony_ci } else if (help.compare(SUPPORTED_ARGS[ARG_HHLOG_LEVEL]) == 0) { 8206f6ba60Sopenharmony_ci std::cout << hhLogLevelHelp_ << std::endl; 8306f6ba60Sopenharmony_ci } else if (help.compare(SUPPORTED_ARGS[ARG_HHLOG_FILE]) == 0) { 8406f6ba60Sopenharmony_ci std::cout << hhLogFileHelp_ << std::endl; 8506f6ba60Sopenharmony_ci } else { 8606f6ba60Sopenharmony_ci std::cout << tipHelp_ << std::endl; 8706f6ba60Sopenharmony_ci } 8806f6ba60Sopenharmony_ci return; 8906f6ba60Sopenharmony_ci}