Skip to content

Commit

Permalink
feat: cmd arg parse
Browse files Browse the repository at this point in the history
  • Loading branch information
Serein207 committed Aug 11, 2024
1 parent 16d4a31 commit e758ec3
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 5 deletions.
18 changes: 18 additions & 0 deletions src/args/cmd_args.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "cmd_args.h"
#include <Version.h>
#include <argparse/argparse.hpp>

CmdArgs parseCmdArgs(int argc, char** argv) {
argparse::ArgumentParser program("yarusto", VERSION_FULL);
program.add_argument("-i", "--input-path")
.help("The input file(.zip) path")
.default_value(std::string("."));
program.add_argument("-o", "--output-path")
.help("The output file(.tar) path")
.default_value(std::string("./out"));

program.parse_args(argc, argv);

return {.inputPath = program.get<std::string>("--input-path"),
.outputPath = program.get<std::string>("--output-path")};
}
10 changes: 10 additions & 0 deletions src/args/cmd_args.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

#include <string>

struct CmdArgs {
std::string inputPath;
std::string outputPath;
};

CmdArgs parseCmdArgs(int argc, char** argv);
5 changes: 0 additions & 5 deletions src/main.cc

This file was deleted.

23 changes: 23 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <args/cmd_args.h>
#include <iostream>

/*
Usage: yarusto [--help] [--version] [--input-path VAR] [--output-path VAR]
Optional arguments:
-h, --help shows help message and exits
-v, --version prints version information and exits
-i, --input-path The input file(.zip) path [nargs=0..1] [default: "."]
-o, --output-path The output file(.tar) path [nargs=0..1] [default: "./out"]
*/

int main(int argc, char** argv) {
CmdArgs args;
try {
args = parseCmdArgs(argc, argv);
} catch (const std::exception& e) {
std::cerr << e.what() << std::endl;
return 1;
}
return 0;
}

0 comments on commit e758ec3

Please sign in to comment.