Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ else()
project(structopt VERSION 0.1.2 LANGUAGES CXX)
endif()

if(EXISTS "${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
conan_basic_setup()
endif()

if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
if (MSVC_VERSION GREATER_EQUAL "1900")
include(CheckCXXCompilerFlag)
Expand All @@ -32,6 +27,7 @@ endif()

option(STRUCTOPT_TESTS "Build structopt tests + enable CTest")
option(STRUCTOPT_SAMPLES "Build structopt samples")
option(STRUCTOPT_EXTERNAL_DEPS "Use external dependencies instead of third party folder" OFF)

include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
Expand All @@ -44,6 +40,16 @@ target_include_directories(structopt INTERFACE
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>)

if (STRUCTOPT_EXTERNAL_DEPS)
find_package(magic_enum REQUIRED CONFIG)
target_link_libraries(structopt INTERFACE magic_enum::magic_enum)
find_package(visit_struct REQUIRED CONFIG)
target_link_libraries(structopt INTERFACE visit_struct::visit_struct)
else()
target_include_directories(structopt INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/third_party>)
endif()

if(STRUCTOPT_SAMPLES)
add_subdirectory(samples)
endif()
Expand Down
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<p align="center">
<img height="70" src="img/logo.png"/>
<img height="70" src="img/logo.png"/>
</p>

<p align="center">
Expand All @@ -10,8 +10,8 @@
<a href="https://github.com/p-ranav/structopt/releases">
<img src="https://img.shields.io/github/release/p-ranav/structopt.svg" alt="ci status"/>
</a>
<a href="https://conan.io/center/structopt/0.1.2">
<img src="https://img.shields.io/badge/Conan-package-blueviolet" alt="conan package"/>
<a href="https://conan.io/center/recipes/structopt">
<img src="https://img.shields.io/conan/v/structopt" alt="conan package"/>
</a>
<a href="https://travis-ci.com/p-ranav/structopt">
<img src="https://travis-ci.com/p-ranav/structopt.svg?branch=master" alt="ci status"/>
Expand Down Expand Up @@ -52,9 +52,9 @@ struct Options {
// the long option can also be provided in kebab case:
// e.g., --bind-address 192.168.5.3
std::optional<std::string> bind_address;

// flag argument
// Use `std::optional<bool>` and provide a default value.
// Use `std::optional<bool>` and provide a default value.
// e.g., -v
// e.g., --verbose
// e.g., -verbose
Expand Down Expand Up @@ -84,7 +84,7 @@ Create a `structopt::app` and parse the command line arguments into the `Options
int main(int argc, char *argv[]) {

try {

// Line of code that does all the work:
auto options = structopt::app("my_app").parse<Options>(argc, argv);

Expand Down Expand Up @@ -154,7 +154,7 @@ files = { file1.txt file3.txt file4.txt }
* [Contributing](#contributing)
* [License](#license)

## Getting Started
## Getting Started

`structopt` is a header-only library. Just add `include/` to your _include_directories_ and you should be good to go. A single header file version is also available in `single_include/`.

Expand Down Expand Up @@ -322,7 +322,7 @@ struct GrepOptions {
// reverse the matching
// enable with `-v`
std::optional<bool> v = false;

// positional arguments
std::string search;
std::string pathspec;
Expand Down Expand Up @@ -364,11 +364,11 @@ Pathspec : bar.txt

### Flag Arguments

Flag arguments are `std::optional<bool>` with a default value.
Flag arguments are `std::optional<bool>` with a default value.

***NOTE*** The default value here is important. It is not a flag if a default value isn't provided. It will simply be an optional argument.
***NOTE*** The default value here is important. It is not a flag if a default value isn't provided. It will simply be an optional argument.

***NOTE*** If `--verbose` is a flag argument with a default value of `false`, then providing the argument will set it to `true`. If `--verbose` does not have a default value, then `structopt` will expect the user to provide a value, e.g., `--verbose true`.
***NOTE*** If `--verbose` is a flag argument with a default value of `false`, then providing the argument will set it to `true`. If `--verbose` does not have a default value, then `structopt` will expect the user to provide a value, e.g., `--verbose true`.

```cpp
#include <structopt/app.hpp>
Expand Down Expand Up @@ -656,7 +656,7 @@ c = [1.5, 3]

#### Integer Literals

`structopt` supports parsing integer literals including hexadecimal, octal, and binary notation.
`structopt` supports parsing integer literals including hexadecimal, octal, and binary notation.

```cpp
#include <structopt/app.hpp>
Expand Down Expand Up @@ -727,10 +727,10 @@ foo@bar:~$ ./main -3.15 +2.717 2E-4 0.1e2 .5 -.3 +5.999

### Nested Structures

With `structopt`, you can define sub-commands, e.g., `git init args` or `git config [flags] args` using nested structures.
With `structopt`, you can define sub-commands, e.g., `git init args` or `git config [flags] args` using nested structures.

* Simply create a nested structure that inherits from `structopt::sub_command`
* You can use `<nested_struct_object>.has_value()` to check if it has been invoked.
* You can use `<nested_struct_object>.has_value()` to check if it has been invoked.

The following program support two sub-commands: `config` and `init`:

Expand Down Expand Up @@ -903,7 +903,7 @@ int main(int argc, char *argv[]) {
}

std::cout << "Args : ";
for (auto& a : options.sed.args) std::cout << a << " ";
for (auto& a : options.sed.args) std::cout << a << " ";
std::cout << "\n";
std::cout << "Pattern : " << options.sed.pattern << "\n";
std::cout << "File : " << options.sed.file << "\n";
Expand Down
82 changes: 0 additions & 82 deletions conanfile.py

This file was deleted.

2 changes: 1 addition & 1 deletion include/structopt/app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <string>
#include <structopt/is_stl_container.hpp>
#include <structopt/parser.hpp>
#include <structopt/third_party/visit_struct/visit_struct.hpp>
#include <visit_struct/visit_struct.hpp>
#include <type_traits>
#include <vector>

Expand Down
6 changes: 3 additions & 3 deletions include/structopt/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#include <structopt/is_number.hpp>
#include <structopt/is_specialization.hpp>
#include <structopt/sub_command.hpp>
#include <structopt/third_party/magic_enum/magic_enum.hpp>
#include <structopt/third_party/visit_struct/visit_struct.hpp>
#include <magic_enum/magic_enum.hpp>
#include <visit_struct/visit_struct.hpp>
#include <tuple>
#include <type_traits>
#include <utility>
Expand Down Expand Up @@ -183,7 +183,7 @@ struct parser {
return result;
}

// Get the optional field name if any from
// Get the optional field name if any from
// e.g., `-v` => `verbose`
// e.g., `-log-level` => `log_level`
std::optional<std::string> get_full_optional_field_name(const std::string& next) {
Expand Down
2 changes: 1 addition & 1 deletion include/structopt/visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <string>
#include <structopt/is_specialization.hpp>
#include <structopt/string.hpp>
#include <structopt/third_party/visit_struct/visit_struct.hpp>
#include <visit_struct/visit_struct.hpp>
#include <type_traits>
#include <vector>

Expand Down
6 changes: 3 additions & 3 deletions single_include.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"project": "Parse command line arguments by defining a struct",
"target": "single_include/structopt/structopt.hpp",
"sources": [
"include/structopt/third_party/visit_struct/visit_struct.hpp",
"include/structopt/third_party/magic_enum/magic_enum.hpp",
"visit_struct/visit_struct.hpp",
"magic_enum/magic_enum.hpp",
"include/structopt/array_size.hpp",
"include/structopt/is_specialization.hpp",
"include/structopt/is_stl_container.hpp",
Expand All @@ -15,5 +15,5 @@
"include/structopt/parser.hpp",
"include/structopt/app.hpp"
],
"include_paths": ["include"]
"include_paths": ["include", "third_party"]
}
5 changes: 1 addition & 4 deletions single_include/structopt/structopt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2552,7 +2552,6 @@ static inline bool is_valid_number(const std::string &input) {
#include <string>
// #include <structopt/is_specialization.hpp>
// #include <structopt/string.hpp>
// #include <structopt/third_party/visit_struct/visit_struct.hpp>
#include <type_traits>
#include <vector>

Expand Down Expand Up @@ -2799,8 +2798,6 @@ class sub_command {
// #include <structopt/is_number.hpp>
// #include <structopt/is_specialization.hpp>
// #include <structopt/sub_command.hpp>
// #include <structopt/third_party/magic_enum/magic_enum.hpp>
// #include <structopt/third_party/visit_struct/visit_struct.hpp>
#include <tuple>
#include <type_traits>
#include <utility>
Expand Down Expand Up @@ -2969,7 +2966,7 @@ struct parser {
return result;
}

// Get the optional field name if any from
// Get the optional field name if any from
// e.g., `-v` => `verbose`
// e.g., `-log-level` => `log_level`
std::optional<std::string> get_full_optional_field_name(const std::string& next) {
Expand Down
4 changes: 2 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ set_source_files_properties(main.cpp
PROPERTIES
COMPILE_DEFINITIONS DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN)
ADD_EXECUTABLE(structopt_tests ${structopt_TEST_SOURCES})
INCLUDE_DIRECTORIES("../include" ".")
target_include_directories(structopt_tests PUBLIC "${CMAKE_SOURCE_DIR}/include" PUBLIC "${CMAKE_SOURCE_DIR}/third_party" PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
target_compile_features(structopt_tests PUBLIC cxx_std_17)
set_target_properties(structopt_tests PROPERTIES OUTPUT_NAME structopt_tests)
set_property(TARGET structopt_tests PROPERTY CXX_STANDARD 17)

# Set ${PROJECT_NAME} as the startup project
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT structopt)
Loading