Skip to content

Commit

Permalink
Use CLI11 command line parser library
Browse files Browse the repository at this point in the history
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
  • Loading branch information
joto committed Dec 22, 2023
1 parent 4a8f42b commit 482719e
Show file tree
Hide file tree
Showing 38 changed files with 12,779 additions and 726 deletions.
20 changes: 0 additions & 20 deletions .github/actions/win-getopt/action.yml

This file was deleted.

3 changes: 0 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,6 @@ jobs:
runs-on: ${{ matrix.os }}

env:
GETOPT_INCLUDE_DIR: ${{ github.workspace }}/../wingetopt/src
GETOPT_LIBRARY: ${{ github.workspace }}/../wingetopt/build/Release/wingetopt.lib
VCPKG_DEFAULT_BINARY_CACHE: C:/vcpkg_binary_cache

steps:
Expand All @@ -428,7 +426,6 @@ jobs:
shell: bash
- uses: ./.github/actions/win-postgres
- uses: ./.github/actions/win-install
- uses: ./.github/actions/win-getopt
- uses: ./.github/actions/win-cmake
- uses: ./.github/actions/win-build
- uses: ./.github/actions/win-test
Expand Down
17 changes: 6 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ endif()
option(EXTERNAL_LIBOSMIUM "Do not use the bundled libosmium" OFF)
option(EXTERNAL_PROTOZERO "Do not use the bundled protozero" OFF)
option(EXTERNAL_FMT "Do not use the bundled fmt" OFF)
option(EXTERNAL_CLI11 "Do not use the bundled CLI11" OFF)

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

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

if (NOT EXTERNAL_CLI11)
set(CLI11_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/contrib/CLI11/include")
endif()

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_BINARY_DIR})

find_package(Osmium 2.17.3 REQUIRED COMPONENTS io)
include_directories(SYSTEM ${OSMIUM_INCLUDE_DIRS} ${PROTOZERO_INCLUDE_DIR} ${FMT_INCLUDE_DIR})
include_directories(SYSTEM ${OSMIUM_INCLUDE_DIRS} ${PROTOZERO_INCLUDE_DIR} ${FMT_INCLUDE_DIR} ${CLI11_INCLUDE_DIR})

if (WITH_LUA)
if (WITH_LUAJIT)
Expand Down Expand Up @@ -261,16 +266,6 @@ endif()

if (WIN32)
list(APPEND LIBS ws2_32)
if (MSVC)
find_path(GETOPT_INCLUDE_DIR getopt.h)
find_library(GETOPT_LIBRARY NAMES wingetopt getopt)
if (GETOPT_INCLUDE_DIR AND GETOPT_LIBRARY)
include_directories(SYSTEM ${GETOPT_INCLUDE_DIR})
list(APPEND LIBS ${GETOPT_LIBRARY})
else()
message(FATAL_ERROR "Can not find getopt library for Windows. Please get it from https://github.com/alex85k/wingetopt or alternative source.")
endif()
endif()
endif()

message(STATUS "Libraries used to build: ${LIBS}")
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ to configure and build itself.

Required libraries are

* [CLI11](https://github.com/CLIUtils/CLI11)
* [expat](https://libexpat.github.io/)
* [proj](https://proj.org/)
* [bzip2](http://www.bzip.org/)
Expand Down
25 changes: 25 additions & 0 deletions contrib/CLI11/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
CLI11 2.2 Copyright (c) 2017-2023 University of Cincinnati, developed by Henry
Schreiner under NSF AWARD 1414736. All rights reserved.

Redistribution and use in source and binary forms of CLI11, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2 changes: 2 additions & 0 deletions contrib/CLI11/README.contrib
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Source: https://github.com/CLIUtils/CLI11
Revision: v2.3.2
Loading

0 comments on commit 482719e

Please sign in to comment.