mirror of
https://onedev.site.tesses.net/tesses-framework
synced 2026-02-08 15:55:46 +00:00
Add args parser
This commit is contained in:
@@ -50,6 +50,7 @@ src/Filesystem/NullFilesystem.cpp
|
|||||||
src/Filesystem/MountableFilesystem.cpp
|
src/Filesystem/MountableFilesystem.cpp
|
||||||
src/Crypto/ClientTLSStream.cpp
|
src/Crypto/ClientTLSStream.cpp
|
||||||
src/Crypto/MbedHelpers.cpp
|
src/Crypto/MbedHelpers.cpp
|
||||||
|
src/Args.cpp
|
||||||
src/TF_Init.cpp
|
src/TF_Init.cpp
|
||||||
src/wrapper.cpp
|
src/wrapper.cpp
|
||||||
src/HiddenField.cpp
|
src/HiddenField.cpp
|
||||||
|
|||||||
13
include/TessesFramework/Args.hpp
Normal file
13
include/TessesFramework/Args.hpp
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "Common.hpp"
|
||||||
|
namespace Tesses::Framework {
|
||||||
|
class Args {
|
||||||
|
public:
|
||||||
|
Args(std::vector<std::string> args);
|
||||||
|
Args(int argc, char** argv);
|
||||||
|
std::string filename;
|
||||||
|
std::vector<std::string> positional;
|
||||||
|
std::vector<std::string> flags;
|
||||||
|
std::vector<std::pair<std::string,std::string>> options;
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -38,3 +38,4 @@
|
|||||||
#include "Platform/Environment.hpp"
|
#include "Platform/Environment.hpp"
|
||||||
#include "Platform/Process.hpp"
|
#include "Platform/Process.hpp"
|
||||||
#include "Serialization/BitConverter.hpp"
|
#include "Serialization/BitConverter.hpp"
|
||||||
|
#include "Args.hpp"
|
||||||
60
src/Args.cpp
Normal file
60
src/Args.cpp
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
#include "TessesFramework/TessesFramework.hpp"
|
||||||
|
|
||||||
|
namespace Tesses::Framework {
|
||||||
|
Args::Args(std::vector<std::string> args)
|
||||||
|
{
|
||||||
|
if(args.size() < 1) return;
|
||||||
|
filename = args[0];
|
||||||
|
bool onlyPos=false;
|
||||||
|
|
||||||
|
for(size_t i = 1; i < args.size(); i++)
|
||||||
|
{
|
||||||
|
std::string& arg = args[i];
|
||||||
|
if(arg == "--")
|
||||||
|
{
|
||||||
|
onlyPos=true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(!onlyPos && arg.size() > 2 && arg[0] == '-' && arg[1] == '-')
|
||||||
|
{
|
||||||
|
auto p = Tesses::Framework::Http::HttpUtils::SplitString(arg.substr(2),"=",2);
|
||||||
|
if(p.size() == 1)
|
||||||
|
flags.push_back(p[0]);
|
||||||
|
else if(p.size() == 2)
|
||||||
|
options.push_back(std::pair<std::string,std::string>(p[0],p[1]));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
positional.push_back(arg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
Args::Args(int argc, char** argv)
|
||||||
|
{
|
||||||
|
if(argc < 1) return;
|
||||||
|
filename = argv[0];
|
||||||
|
bool onlyPos=false;
|
||||||
|
|
||||||
|
for(int i = 1; i < argc; i++)
|
||||||
|
{
|
||||||
|
std::string_view arg = argv[i];
|
||||||
|
if(arg == "--")
|
||||||
|
{
|
||||||
|
onlyPos=true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(!onlyPos && arg.size() > 2 && arg[0] == '-' && arg[1] == '-')
|
||||||
|
{
|
||||||
|
auto p = Tesses::Framework::Http::HttpUtils::SplitString((std::string)arg.substr(2),"=",2);
|
||||||
|
if(p.size() == 1)
|
||||||
|
flags.push_back(p[0]);
|
||||||
|
else if(p.size() == 2)
|
||||||
|
options.push_back(std::pair<std::string,std::string>(p[0],p[1]));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
positional.push_back((std::string)arg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user