test: Update 4 files
Some checks failed
Build-Test-Publish / build (linux/arm64) (push) Failing after 13s
Build-Test-Publish / build (linux/amd64) (push) Failing after 31s
Build-Test-Publish / test-install-from-scratch (linux/amd64) (push) Has been skipped
Build-Test-Publish / test-install-from-scratch (linux/arm64) (push) Has been skipped

This commit is contained in:
Your Name 2025-06-25 18:45:31 +12:00
parent a12270f6c2
commit 6ed73ef5a8
4 changed files with 34 additions and 13 deletions

View File

@ -4,6 +4,7 @@
struct Args {
bool silent = false;
bool update = false;
bool version = false;
std::string source;
std::string dest;
};

View File

@ -10,28 +10,39 @@ Usage: dehydrate [OPTIONS] SOURCE DEST
Options:
-s Silent mode (no output)
-u Update dehydrate to the latest version
-v Show version only
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
dehydrate -v Shows version number
)";
Args parse_args(int argc, char* argv[]) {
Args args;
int idx = 1;
// Check for silent flag
if (idx < argc && std::string(argv[idx]) == "-s") {
args.silent = true;
// Parse flags
while (idx < argc && argv[idx][0] == '-') {
std::string flag = argv[idx];
if (flag == "-s") {
args.silent = true;
} else if (flag == "-u") {
args.update = true;
} else if (flag == "-v") {
args.version = true;
} else {
throw std::runtime_error("Unknown flag: " + flag + "\n\n" + HELP_TEXT);
}
idx++;
}
// 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
// If update or version flag is set, return early
if (args.update || args.version) {
return args;
}
// Require source and dest parameters for normal operation

View File

@ -57,14 +57,23 @@ int update()
int main(int argc, char* argv[]) {
try {
std::cout << "Dehydrate version " << VERSION << std::endl;
Args args = parse_args(argc, argv);
// Handle version request (output only version)
if (args.version) {
std::cout << VERSION << std::endl;
return 0;
}
// Handle update request
if (args.update) {
std::cout << "Dehydrate version " << VERSION << std::endl;
return update();
}
// Show version for normal operations
std::cout << "Dehydrate version " << VERSION << std::endl;
std::filesystem::path src(args.source);
if (!std::filesystem::exists(src)) {
std::cerr << "Source does not exist: " << args.source << std::endl;

View File

@ -59,11 +59,11 @@ fi
echo "Using dehydrate binary: $DEHYDRATE"
# Test 1: Version command (dehydrate shows version in help output)
# Test 1: Version command (dehydrate -v shows version only)
echo "Test 1: Version command"
VERSION_OUTPUT=$("$DEHYDRATE" 2>&1 || true)
# Extract version from the beginning of help output
VERSION=$(echo "$VERSION_OUTPUT" | head -n 1 | sed 's/Dehydrate version //')
VERSION_OUTPUT=$("$DEHYDRATE" -v 2>&1 || true)
# Version output should be just the version number
VERSION=$(echo "$VERSION_OUTPUT" | head -n 1)
if [[ "$VERSION" =~ ^[0-9]{4}\.[0-9]{4}\.[0-9]{4}$ ]]; then
print_test_result "Version format (YYYY.MMDD.HHMM)" 0
else