Skip to content

Commit 482719e

Browse files
committed
Use CLI11 command line parser library
This switches parsing of command line arguments from getopt to the CLI11 library. Its adds CLI11 as a new dependency. With this commit CLI11 is vendored in in the contrib directory, because it is not available in Ubuntu 20.04 and Debian before Bookworm. It is available in Ubuntu 22.04 und Debian Bookworm and it is available in Homebrew and as vcpkg. So a bit down the line we can switch to the versions available from the OS distribution. For Windows we don't need the getopt version from alex85k any more and this commit also removes that code from the Github action setup. This commit is quite large, because we have to change everything at the same time. Changes are for osm2pgsql and osm2pgsql-gen which now share part of the option parsing code (database and logging options), in the new src/command-line-app.[ch]pp files. The code tries to keep the functionality the same as much as possible. So no extra checks on command line options or so, these can come later. There are some unavoidable changes: * Some error messages have changed * Help output is now generated by the CLI11 library so it looks very different. There is no verbose help version any more. All command line options are shown with --help, but some with a bit less detail than before. But all the detail is in the man page anyway. * CLI11 can not parse an empty option parameter, so something like "--foo=" does not work, it tries to use the next option as value for the option. This is not very relevant in the real world, but there might be some corner cases where this changes behaviour. See #142
1 parent 4a8f42b commit 482719e

38 files changed

+12779
-726
lines changed

.github/actions/win-getopt/action.yml

Lines changed: 0 additions & 20 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,6 @@ jobs:
405405
runs-on: ${{ matrix.os }}
406406

407407
env:
408-
GETOPT_INCLUDE_DIR: ${{ github.workspace }}/../wingetopt/src
409-
GETOPT_LIBRARY: ${{ github.workspace }}/../wingetopt/build/Release/wingetopt.lib
410408
VCPKG_DEFAULT_BINARY_CACHE: C:/vcpkg_binary_cache
411409

412410
steps:
@@ -428,7 +426,6 @@ jobs:
428426
shell: bash
429427
- uses: ./.github/actions/win-postgres
430428
- uses: ./.github/actions/win-install
431-
- uses: ./.github/actions/win-getopt
432429
- uses: ./.github/actions/win-cmake
433430
- uses: ./.github/actions/win-build
434431
- uses: ./.github/actions/win-test

CMakeLists.txt

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ endif()
5555
option(EXTERNAL_LIBOSMIUM "Do not use the bundled libosmium" OFF)
5656
option(EXTERNAL_PROTOZERO "Do not use the bundled protozero" OFF)
5757
option(EXTERNAL_FMT "Do not use the bundled fmt" OFF)
58+
option(EXTERNAL_CLI11 "Do not use the bundled CLI11" OFF)
5859

5960
set(USE_PROJ_LIB "auto" CACHE STRING "Which version of PROJ API to use: ('4', '6', 'off', or 'auto')")
6061

@@ -175,10 +176,14 @@ if (NOT EXTERNAL_FMT)
175176
set(FMT_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/contrib/fmt/include")
176177
endif()
177178

179+
if (NOT EXTERNAL_CLI11)
180+
set(CLI11_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/contrib/CLI11/include")
181+
endif()
182+
178183
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_BINARY_DIR})
179184

180185
find_package(Osmium 2.17.3 REQUIRED COMPONENTS io)
181-
include_directories(SYSTEM ${OSMIUM_INCLUDE_DIRS} ${PROTOZERO_INCLUDE_DIR} ${FMT_INCLUDE_DIR})
186+
include_directories(SYSTEM ${OSMIUM_INCLUDE_DIRS} ${PROTOZERO_INCLUDE_DIR} ${FMT_INCLUDE_DIR} ${CLI11_INCLUDE_DIR})
182187

183188
if (WITH_LUA)
184189
if (WITH_LUAJIT)
@@ -261,16 +266,6 @@ endif()
261266

262267
if (WIN32)
263268
list(APPEND LIBS ws2_32)
264-
if (MSVC)
265-
find_path(GETOPT_INCLUDE_DIR getopt.h)
266-
find_library(GETOPT_LIBRARY NAMES wingetopt getopt)
267-
if (GETOPT_INCLUDE_DIR AND GETOPT_LIBRARY)
268-
include_directories(SYSTEM ${GETOPT_INCLUDE_DIR})
269-
list(APPEND LIBS ${GETOPT_LIBRARY})
270-
else()
271-
message(FATAL_ERROR "Can not find getopt library for Windows. Please get it from https://github.com/alex85k/wingetopt or alternative source.")
272-
endif()
273-
endif()
274269
endif()
275270

276271
message(STATUS "Libraries used to build: ${LIBS}")

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ to configure and build itself.
4343

4444
Required libraries are
4545

46+
* [CLI11](https://github.com/CLIUtils/CLI11)
4647
* [expat](https://libexpat.github.io/)
4748
* [proj](https://proj.org/)
4849
* [bzip2](http://www.bzip.org/)

contrib/CLI11/LICENSE

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
CLI11 2.2 Copyright (c) 2017-2023 University of Cincinnati, developed by Henry
2+
Schreiner under NSF AWARD 1414736. All rights reserved.
3+
4+
Redistribution and use in source and binary forms of CLI11, with or without
5+
modification, are permitted provided that the following conditions are met:
6+
7+
1. Redistributions of source code must retain the above copyright notice, this
8+
list of conditions and the following disclaimer.
9+
2. Redistributions in binary form must reproduce the above copyright notice,
10+
this list of conditions and the following disclaimer in the documentation
11+
and/or other materials provided with the distribution.
12+
3. Neither the name of the copyright holder nor the names of its contributors
13+
may be used to endorse or promote products derived from this software without
14+
specific prior written permission.
15+
16+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
20+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
23+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

contrib/CLI11/README.contrib

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Source: https://github.com/CLIUtils/CLI11
2+
Revision: v2.3.2

0 commit comments

Comments
 (0)