mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2025-03-21 15:49:53 +01:00
More work on the new param system
This commit is contained in:
parent
a87aedabb8
commit
5c138aa4a5
@ -1,4 +1,24 @@
|
|||||||
#include "command_args.h"
|
#include "command_args.h"
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
|
void CommandArgsParser::defineAll() {
|
||||||
|
#if defined(_WIN32)
|
||||||
|
std::string root = ".";
|
||||||
|
define('c', "con", "Show console on Windows");
|
||||||
|
#elif defined(IS_MACOS_BUNDLE)
|
||||||
|
std::string root = (std::string)getenv("HOME") + "/Library/Application Support/sdrpp";
|
||||||
|
#elif defined(__ANDROID__)
|
||||||
|
std::string root = "/storage/self/primary/sdrpp";
|
||||||
|
#else
|
||||||
|
std::string root = (std::string)getenv("HOME") + "/.config/sdrpp";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
define('a', "addr", "Server mode address", "0.0.0.0");
|
||||||
|
define('h', "help", "Show help");
|
||||||
|
define('p', "port", "Server mode port", 5259);
|
||||||
|
define('r', "root", "Root directory, where all config files are stored", std::filesystem::absolute(root).string());
|
||||||
|
define('s', "server", "Run in server mode");
|
||||||
|
}
|
||||||
|
|
||||||
int CommandArgsParser::parse(int argc, char* argv[]) {
|
int CommandArgsParser::parse(int argc, char* argv[]) {
|
||||||
for (int i = 1; i < argc; i++) {
|
for (int i = 1; i < argc; i++) {
|
||||||
@ -94,10 +114,10 @@ int CommandArgsParser::parse(int argc, char* argv[]) {
|
|||||||
void CommandArgsParser::showHelp() {
|
void CommandArgsParser::showHelp() {
|
||||||
for (auto const& [ln, arg] : args) {
|
for (auto const& [ln, arg] : args) {
|
||||||
if (arg.alias) {
|
if (arg.alias) {
|
||||||
printf("-%c\t--%s\t\t%s\n", arg.alias, ln.c_str(), arg.description.c_str());
|
printf("-%c --%s\t\t%s\n", arg.alias, ln.c_str(), arg.description.c_str());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
printf(" \t--%s\t\t%s\n", ln.c_str(), arg.description.c_str());
|
printf(" --%s\t\t%s\n", ln.c_str(), arg.description.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -48,7 +48,6 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
CLIArg(char al, std::string desc, std::string s) {
|
CLIArg(char al, std::string desc, std::string s) {
|
||||||
printf("String const called\n");
|
|
||||||
alias = al;
|
alias = al;
|
||||||
description = desc;
|
description = desc;
|
||||||
type = CLI_ARG_TYPE_STRING;
|
type = CLI_ARG_TYPE_STRING;
|
||||||
@ -56,7 +55,6 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
CLIArg(char al, std::string desc, const char* s) {
|
CLIArg(char al, std::string desc, const char* s) {
|
||||||
printf("String const called\n");
|
|
||||||
alias = al;
|
alias = al;
|
||||||
description = desc;
|
description = desc;
|
||||||
type = CLI_ARG_TYPE_STRING;
|
type = CLI_ARG_TYPE_STRING;
|
||||||
@ -108,6 +106,8 @@ public:
|
|||||||
aliases[shortName] = name;
|
aliases[shortName] = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void defineAll();
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
void define(char shortName, std::string name, std::string desc, T defValue) {
|
void define(char shortName, std::string name, std::string desc, T defValue) {
|
||||||
args[name] = CLIArg(shortName, desc, defValue);
|
args[name] = CLIArg(shortName, desc, defValue);
|
||||||
|
@ -37,6 +37,7 @@ namespace core {
|
|||||||
ConfigManager configManager;
|
ConfigManager configManager;
|
||||||
ModuleManager moduleManager;
|
ModuleManager moduleManager;
|
||||||
ModuleComManager modComManager;
|
ModuleComManager modComManager;
|
||||||
|
CommandArgsParser args;
|
||||||
|
|
||||||
void setInputSampleRate(double samplerate) {
|
void setInputSampleRate(double samplerate) {
|
||||||
// Forward this to the server
|
// Forward this to the server
|
||||||
@ -64,6 +65,16 @@ int sdrpp_main(int argc, char* argv[]) {
|
|||||||
chdir(execPath.parent_path().string().c_str());
|
chdir(execPath.parent_path().string().c_str());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Define command line options and parse arguments
|
||||||
|
core::args.defineAll();
|
||||||
|
core::args.parse(argc, argv);
|
||||||
|
|
||||||
|
// Show help and exit if requested
|
||||||
|
if ((bool)core::args["help"]) {
|
||||||
|
core::args.showHelp();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Load default options and parse command line
|
// Load default options and parse command line
|
||||||
options::loadDefaults();
|
options::loadDefaults();
|
||||||
if (!options::parse(argc, argv)) { return -1; }
|
if (!options::parse(argc, argv)) { return -1; }
|
||||||
|
@ -3,11 +3,13 @@
|
|||||||
#include <module.h>
|
#include <module.h>
|
||||||
#include <module.h>
|
#include <module.h>
|
||||||
#include <module_com.h>
|
#include <module_com.h>
|
||||||
|
#include "command_args.h"
|
||||||
|
|
||||||
namespace core {
|
namespace core {
|
||||||
SDRPP_EXPORT ConfigManager configManager;
|
SDRPP_EXPORT ConfigManager configManager;
|
||||||
SDRPP_EXPORT ModuleManager moduleManager;
|
SDRPP_EXPORT ModuleManager moduleManager;
|
||||||
SDRPP_EXPORT ModuleComManager modComManager;
|
SDRPP_EXPORT ModuleComManager modComManager;
|
||||||
|
SDRPP_EXPORT CommandArgsParser args;
|
||||||
|
|
||||||
void setInputSampleRate(double samplerate);
|
void setInputSampleRate(double samplerate);
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user