Compare commits
3 Commits
b59fe1857e
...
608767f5c2
Author | SHA1 | Date |
---|---|---|
BodgeMaster | 608767f5c2 | |
BodgeMaster | e31bff0802 | |
BodgeMaster | 5c73308934 |
|
@ -13,13 +13,12 @@
|
|||
// version 3 along with this program.
|
||||
// If not, see https://www.gnu.org/licenses/agpl-3.0.en.html
|
||||
|
||||
#include "cli.h++"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include "error.h++"
|
||||
#include "cli.hpp"
|
||||
#include "error.hpp"
|
||||
|
||||
namespace CLI {
|
||||
Flag::Flag() {
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include "error.h++"
|
||||
#include "error.hpp"
|
||||
|
||||
namespace CLI {
|
||||
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
// Copyright 2022, FOSS-VG Developers and Contributers
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Affero General Public License as published
|
||||
// by the Free Software Foundation, version 3.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied
|
||||
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
// See the GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// version 3 along with this program.
|
||||
// If not, see https://www.gnu.org/licenses/agpl-3.0.en.html
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include "error.hpp"
|
||||
|
||||
namespace CLI {
|
||||
|
||||
struct Flag {
|
||||
char shortName;
|
||||
std::string longName;
|
||||
// used for automatic usage generation
|
||||
std::string description;
|
||||
|
||||
bool present;
|
||||
|
||||
Flag();
|
||||
Flag(char shortName, std::string longName, std::string description);
|
||||
};
|
||||
|
||||
struct Option {
|
||||
char shortName;
|
||||
std::string longName;
|
||||
// used for automatic usage generation
|
||||
std::string description;
|
||||
std::string placeholder; // the "COUNT" in "ping [-c <COUNT>] <HOST>"
|
||||
|
||||
bool present;
|
||||
std::string value;
|
||||
|
||||
Option();
|
||||
Option(char shortName, std::string longName, std::string placeholder, std::string description);
|
||||
};
|
||||
|
||||
struct Argument {
|
||||
// used for automatic usage generation
|
||||
std::string description;
|
||||
std::string placeholder; // the "HOST" in "ping [-c <COUNT>] <HOST>"
|
||||
|
||||
bool present;
|
||||
std::string value;
|
||||
|
||||
Argument();
|
||||
Argument(std::string placeholder, std::string description);
|
||||
};
|
||||
|
||||
class ArgumentsParser {
|
||||
private:
|
||||
std::map<char, Flag*> flagsByShortName;
|
||||
std::map<std::string, Flag*> flagsByLongName;
|
||||
std::map<char, Option*> optionsByShortName;
|
||||
std::map<std::string, Option*> optionsByLongName;
|
||||
std::vector<Argument> arguments;
|
||||
std::string description;
|
||||
std::string additionalInfo;
|
||||
|
||||
public:
|
||||
std::string programName;
|
||||
bool wrongUsage;
|
||||
std::vector<std::string> wrongUsageMessages;
|
||||
|
||||
// using int here bc that's how main() is defined
|
||||
ArgumentsParser(int argc, const char* const argv[], std::vector<Flag> flags, std::vector<Option> options, std::vector<Argument> arguments);
|
||||
ArgumentsParser(int argc, const char* const argv[], std::vector<Flag> flags, std::vector<Option> options, std::vector<Argument> arguments, std::string description);
|
||||
ArgumentsParser(int argc, const char* const argv[], std::vector<Flag> flags, std::vector<Option> options, std::vector<Argument> arguments, std::string description, std::string additionalInfo);
|
||||
~ArgumentsParser();
|
||||
|
||||
ErrorOr<bool> getFlag(char shortName);
|
||||
ErrorOr<bool> getFlag(std::string longName);
|
||||
ErrorOr<std::string> getArgument(std::vector<CLI::Argument>::size_type position);
|
||||
ErrorOr<std::string> getOption(char shortName);
|
||||
ErrorOr<std::string> getOption(std::string longName);
|
||||
|
||||
std::string getUsage();
|
||||
};
|
||||
|
||||
}
|
|
@ -15,8 +15,8 @@
|
|||
|
||||
#include <tinyutf8/tinyutf8.h>
|
||||
#include <string>
|
||||
#include "error.h++"
|
||||
#include "javacompat.h++"
|
||||
#include "error.hpp"
|
||||
#include "javacompat.hpp"
|
||||
#include "../../.endianness"
|
||||
|
||||
#ifdef FOSSVG_ENDIAN_BIG_WORD
|
||||
|
|
|
@ -13,9 +13,9 @@
|
|||
//version 3 along with this program.
|
||||
//If not, see https://www.gnu.org/licenses/agpl-3.0.en.html
|
||||
|
||||
#include <tinyutf8/tinyutf8.h>
|
||||
#include "error.h++"
|
||||
#include <vector>
|
||||
#include <tinyutf8/tinyutf8.h>
|
||||
#include "error.hpp"
|
||||
|
||||
namespace JavaCompat {
|
||||
ErrorOr<tiny_utf8::string> importJavaString(uint8_t data[], uint16_t size);
|
|
@ -19,9 +19,9 @@
|
|||
#include <tinyutf8/tinyutf8.h>
|
||||
#include <iostream>
|
||||
|
||||
#include "nbt.h++"
|
||||
#include "error.h++"
|
||||
#include "javacompat.h++"
|
||||
#include "nbt.hpp"
|
||||
#include "error.hpp"
|
||||
#include "javacompat.hpp"
|
||||
|
||||
|
||||
#include "../../.endianness"
|
||||
|
@ -156,7 +156,7 @@ namespace NBT {
|
|||
if(dataSize > 0xFFFF){
|
||||
return ErrorOr<tiny_utf8::string>(true, ErrorCodes::OVERRUN);
|
||||
}
|
||||
|
||||
|
||||
ErrorOr<tiny_utf8::string> output = JavaCompat::importJavaString(data+currentPosition, (uint16_t) dataSize);
|
||||
if(output.isError){
|
||||
return ErrorOr<tiny_utf8::string>(true, output.errorCode);
|
||||
|
|
|
@ -37,8 +37,8 @@
|
|||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include "error.h++"
|
||||
#include <tinyutf8/tinyutf8.h>
|
||||
#include "error.hpp"
|
||||
|
||||
namespace NBT {
|
||||
namespace helper {
|
|
@ -16,10 +16,10 @@
|
|||
#include <string>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include "assert.h++"
|
||||
#include "../lib/error.h++"
|
||||
#include "assert.hpp"
|
||||
#include "../lib/error.hpp"
|
||||
|
||||
#include "../lib/cli.h++"
|
||||
#include "../lib/cli.hpp"
|
||||
|
||||
int main() {
|
||||
std::cout << "################################################################################" << std::endl;
|
||||
|
|
|
@ -13,12 +13,12 @@
|
|||
// version 3 along with this program.
|
||||
// If not, see https://www.gnu.org/licenses/agpl-3.0.en.html
|
||||
|
||||
#include "assert.h++"
|
||||
#include "../lib/javacompat.h++"
|
||||
#include <iostream>
|
||||
#include <tinyutf8/tinyutf8.h>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include "assert.hpp"
|
||||
#include "../lib/javacompat.hpp"
|
||||
|
||||
|
||||
int main(){
|
||||
|
|
|
@ -18,11 +18,11 @@
|
|||
#include <vector>
|
||||
#include <fstream>
|
||||
|
||||
#include "assert.h++"
|
||||
#include "assert.hpp"
|
||||
|
||||
#include "../lib/nbt.h++"
|
||||
#include "../lib/error.h++"
|
||||
#include "../lib/javacompat.h++"
|
||||
#include "../lib/nbt.hpp"
|
||||
#include "../lib/error.hpp"
|
||||
#include "../lib/javacompat.hpp"
|
||||
|
||||
int main(){
|
||||
std::cout << "################################################################################" << std::endl;
|
||||
|
|
|
@ -1,9 +1,24 @@
|
|||
// Copyright 2022, FOSS-VG Developers and Contributers
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Affero General Public License as published
|
||||
// by the Free Software Foundation, version 3.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied
|
||||
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
// See the GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// version 3 along with this program.
|
||||
// If not, see https://www.gnu.org/licenses/agpl-3.0.en.html
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include "../lib/nbt.h++"
|
||||
#include "../lib/error.h++"
|
||||
#include "../lib/javacompat.h++"
|
||||
#include "../lib/nbt.hpp"
|
||||
#include "../lib/error.hpp"
|
||||
#include "../lib/javacompat.hpp"
|
||||
|
||||
int main() {
|
||||
std::cout << "================================================================================" << std::endl;
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
// version 3 along with this program.
|
||||
// If not, see https://www.gnu.org/licenses/agpl-3.0.en.html
|
||||
|
||||
#include "../lib/nbt.h++"
|
||||
#include "../lib/nbt.hpp"
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
return 0;
|
||||
|
|
|
@ -23,8 +23,8 @@
|
|||
#include <mutex>
|
||||
#include <csignal>
|
||||
|
||||
#include "../lib/error.h++"
|
||||
#include "../lib/cli.h++"
|
||||
#include "../lib/error.hpp"
|
||||
#include "../lib/cli.hpp"
|
||||
|
||||
#define EXIT_SUCCESS 0
|
||||
#define EXIT_RUNTIME 1
|
||||
|
@ -96,10 +96,20 @@ int main(int argc, char* argv[]){
|
|||
flags.push_back(CLI::Flag('6', "ipv6", "use IPv6, defaults to both when -4 and -6 are omitted, otherwise uses what is specified"));
|
||||
flags.push_back(CLI::Flag('t', "tcp", "use TCP, defaults to both when -t and -u are omitted, otherwise uses what is specified"));
|
||||
flags.push_back(CLI::Flag('u', "udp", "use UDP, defaults to both when -t and -u are omitted, otherwise uses what is specified"));
|
||||
flags.push_back(CLI::Flag('n', "no-color", "disable coloring the output (intended for terminals that don't work well with color escape sequences)"));
|
||||
flags.push_back(CLI::Flag('e', "echo-back", "echo input back to stdout"));
|
||||
|
||||
std::vector<CLI::Option> options;
|
||||
options.push_back(CLI::Option('c', "connect", "HOST", "connect to HOST, listen for incoming connections if omitted"));
|
||||
options.push_back(CLI::Option('m', "mtu-optimize", "MTU", "Optimize for a specific maximum transfer unit by reading MTU bytes at a time."));
|
||||
options.push_back(CLI::Option(
|
||||
'p', "print-prefixes", "TCPv4i:UDPv4i:TCPv6i:UDPv6i:TCPv4o:UDPv4o:TCPv6o:UDPv6o",
|
||||
"override default prefixes for output (defaults to spaces + coloring the output or \"t4:u4:t6:u6:T4:U4:T6:U6\" in no-color mode)"
|
||||
));
|
||||
options.push_back(CLI::Option(
|
||||
'i', "input-prefixes", "TCP:UDP:IPv4:IPv6",
|
||||
"override default prefixes for input (defaults to \"t:u:4:6\")"
|
||||
));
|
||||
|
||||
std::vector<CLI::Argument> arguments;
|
||||
arguments.push_back(CLI::Argument("PORT", "the port to use"));
|
||||
|
|
Loading…
Reference in New Issue