Skip to content

Commit

Permalink
修改 program_options
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown committed Sep 10, 2018
1 parent 4554bc0 commit ef27195
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
include Makefile.common

# TEST_APP = test_emplace
TEST_APP = test_json
TEST_APP = csar

.PHONY: all build-static build-shared check clean distclean test
all: build-static check test
Expand All @@ -15,7 +15,6 @@ check: build-static
$(MAKE) -C test

test:
./build/$(TEST_APP).exe

clean:
$(MAKE) -C src clean
Expand Down
3 changes: 2 additions & 1 deletion Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ BUILD_DIR := ../build
RESULT_DIR := $(BUILD_DIR)/
CACHE_DIR := $(BUILD_DIR)/cache

EXEFLAGS := -m64
EXEFLAGS := $(LDFLAGS)
EXEFLAGS += -m64


$(CACHE_DIR)/%.o : %.cpp
Expand Down
30 changes: 25 additions & 5 deletions src/csar.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,37 @@
#include <iostream>
#include <exception>
#include <boost/program_options/cmdline.hpp>
#include <boost/program_options/options_description.hpp>
#include <boost/program_options.hpp>

struct NotImplementedError: public std::exception
{
};

namespace po = boost::program_options;

int main(int argc, char const *argv[])
{
using options_description = boost::program_options::options_description;
options_description desc("Allowed options:");
std::cout << "Hello world!" << std::endl;
po::options_description desc("Arguments: ");
desc.add_options()
("help", "produce help messages")
("input-file", po::value< std::string >(), "input file path")
("output", po::value< std::string >(), "output file path")
;
po::positional_options_description p;
p.add("input-file", -1);

po::variables_map vm;
po::store(po::command_line_parser(argc, argv).
options(desc).positional(p).run(), vm);
po::notify(vm);

if (vm.count("help")) {
std::cout << "Usage: options_description [options]\n";
std::cout << desc << std::endl;
return 0;
}
if (vm.count("output"))
{
// std::cout << desc["output"].as<std::string>() << std::endl;
}
return 0;
}
5 changes: 3 additions & 2 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ OBJECTS :=

EXEUTABLES := $(foreach f,$(SOURCES:.cpp=.exe),$(BUILD_DIR)/$(f))

.PHONY: all build clean
.PHONY: all build clean test
all: build
build: $(EXEUTABLES)
test: build

$(BUILD_DIR)/%.exe: %.o $(OBJECTS)
$(CXX) $(CXXFLAGS) -o $@ $^
$(CXX) $(CXXFLAGS) $(EXEFLAGS) -o $@ $^

clean:
$(RM) $(EXEUTABLES)
Expand Down

0 comments on commit ef27195

Please sign in to comment.