Tidy
This commit is contained in:
parent
ac29436f35
commit
153b2e4843
20
README.md
20
README.md
@ -13,17 +13,21 @@ curl -fsSL -o dehydrate https://gitea.jde.nz/public/dehydrate/releases/download/
|
||||
|
||||
## How it Works
|
||||
|
||||
Dehydrate converts existing files to C++ source code which can be used to recreate the original files.
|
||||
Works on individual files or entire directory trees.
|
||||
|
||||
Given a source file or folder, creates c++ code to recreate that file/folder.
|
||||
If it's a folder, it recreates the entire tree (all subfolders and files within).
|
||||
|
||||
Use:
|
||||
```
|
||||
Usage:
|
||||
dehydrate [-s] SOURCEFILE DESTFOLDER Creates _SOURCEFILE.CPP and _SOURCEFILE.HPP in DESTFOLDER
|
||||
dehydrate [-s] SOURCEFOLDER DESTFOLDER Creates _SOURCEFOLDER.CPP and _SOURCEFOLDER.HPP in DESTFOLDER
|
||||
|
||||
-s = silent (no output)
|
||||
Usage: dehydrate [OPTIONS] SOURCE DEST
|
||||
|
||||
Options:
|
||||
-s Silent mode (no output)
|
||||
-u Update dehydrate to the latest version
|
||||
|
||||
Examples:
|
||||
dehydrate file.txt output/ Creates _file.txt.cpp and _file.txt.hpp in output/
|
||||
dehydrate src/ output/ Creates _src.cpp and _src.hpp in output/
|
||||
dehydrate -u Updates dehydrate to the latest version
|
||||
```
|
||||
|
||||
All c++ code produced is in namespace `recreate_{SOURCEFILE|SOURCEFOLDER}`
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
struct Args {
|
||||
bool silent = false;
|
||||
bool update = false;
|
||||
std::string source;
|
||||
std::string dest;
|
||||
};
|
||||
|
@ -1,16 +1,43 @@
|
||||
#include "argparse.hpp"
|
||||
#include <stdexcept>
|
||||
|
||||
static const std::string HELP_TEXT = R"(
|
||||
Converts existing files to C++ source code which can be used to recreate the original files.
|
||||
|
||||
Usage: dehydrate [OPTIONS] SOURCE DEST
|
||||
|
||||
Options:
|
||||
-s Silent mode (no output)
|
||||
-u Update dehydrate to the latest version
|
||||
|
||||
Examples:
|
||||
dehydrate file.txt output/ Creates _file.txt.cpp and _file.txt.hpp in output/
|
||||
dehydrate src/ output/ Creates _src.cpp and _src.hpp in output/
|
||||
dehydrate -u Updates dehydrate to the latest version
|
||||
)";
|
||||
|
||||
Args parse_args(int argc, char* argv[]) {
|
||||
Args args;
|
||||
int idx = 1;
|
||||
if (argc > 1 && std::string(argv[1]) == "-s") {
|
||||
|
||||
// Check for silent flag
|
||||
if (idx < argc && std::string(argv[idx]) == "-s") {
|
||||
args.silent = true;
|
||||
idx++;
|
||||
}
|
||||
if (argc - idx != 2) {
|
||||
throw std::runtime_error("Usage: dehydrate [-s] SOURCE DESTFOLDER");
|
||||
|
||||
// Check for update flag
|
||||
if (idx < argc && std::string(argv[idx]) == "-u") {
|
||||
args.update = true;
|
||||
idx++;
|
||||
return args; // No need for source and dest parameters when updating
|
||||
}
|
||||
|
||||
// Require source and dest parameters for normal operation
|
||||
if (argc - idx != 2) {
|
||||
throw std::runtime_error(HELP_TEXT);
|
||||
}
|
||||
|
||||
args.source = argv[idx];
|
||||
args.dest = argv[idx + 1];
|
||||
return args;
|
||||
|
@ -58,6 +58,12 @@ int update()
|
||||
int main(int argc, char* argv[]) {
|
||||
try {
|
||||
Args args = parse_args(argc, argv);
|
||||
|
||||
// Handle update request
|
||||
if (args.update) {
|
||||
return update();
|
||||
}
|
||||
|
||||
std::filesystem::path src(args.source);
|
||||
if (!std::filesystem::exists(src)) {
|
||||
std::cerr << "Source does not exist: " << args.source << std::endl;
|
||||
|
Loading…
x
Reference in New Issue
Block a user