#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;
    
    // Check for silent flag
    if (idx < argc && std::string(argv[idx]) == "-s") {
        args.silent = true;
        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
    }
    
    // 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;
} 