Skip to content

Commit 747ca84

Browse files
authored
Merge pull request seqan#297 from eseiler/misc/finish
synopsis fix and maintenance
2 parents efa28c8 + 2502d59 commit 747ca84

23 files changed

+132
-62
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
mygit
22
=====
3-
subcommand_parse_snippet -f|--flag
3+
subcommand_parse_snippet [-f|--flag]
44
Try -h or --help for more information.

doc/tutorial/parser/solution3.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Game-of-Parsing - Aggregate average Game of Thrones viewers by season.
22
======================================================================
3-
solution3_snippet -H|--header-is-set [-y|--year uint32] [-a|--aggregate-by
4-
string] [--] path
3+
solution3_snippet [-H|--header-is-set] [-y|--year uint32]
4+
[-a|--aggregate-by string] [--] path
55
Try -h or --help for more information.

doc/tutorial/parser/solution4.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Game-of-Parsing - Aggregate average Game of Thrones viewers by season.
22
======================================================================
3-
solution4_snippet -H|--header-is-set [-s|--season uint8]...
3+
solution4_snippet [-H|--header-is-set] [-s|--season uint8]...
44
[-a|--aggregate-by string] [--] path
55
Try -h or --help for more information.

doc/tutorial/parser/solution5.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Game-of-Parsing - Aggregate average Game of Thrones viewers by season.
22
======================================================================
3-
solution5_snippet -H|--header-is-set -s|--season uint8 [-s|--season
3+
solution5_snippet [-H|--header-is-set] -s|--season uint8 [-s|--season
44
uint8]... [-a|--aggregate-by string] [--] path
55
Try -h or --help for more information.

doc/tutorial/parser/solution6.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Game-of-Parsing - Aggregate average Game of Thrones viewers by season.
22
======================================================================
3-
solution6_snippet -H|--header-is-set -s|--season uint8 [-s|--season
3+
solution6_snippet [-H|--header-is-set] -s|--season uint8 [-s|--season
44
uint8]... [-a|--aggregate-by string] [--] path
55
Try -h or --help for more information.

include/sharg/detail/format_base.hpp

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -734,17 +734,20 @@ class format_help_base : public format_base
734734
}
735735
#endif
736736

737-
auto positional_subrange =
738-
std::ranges::partition(synopsis_elements, std::logical_not{}, &synopsis_element::is_positional);
737+
std::ranges::stable_sort(synopsis_elements, std::ranges::less{}, &synopsis_element::type);
738+
auto const pivot = std::ranges::lower_bound(synopsis_elements,
739+
synopsis_element::option_type::positional,
740+
std::ranges::less{},
741+
&synopsis_element::type);
739742

740-
for (auto it = synopsis_elements.begin(); it != positional_subrange.begin(); ++it)
743+
for (auto it = synopsis_elements.begin(); it != pivot; ++it)
741744
{
742745
synopsis_line += " " + it->option_str;
743746
}
744-
if (!std::ranges::empty(positional_subrange))
747+
if (pivot != synopsis_elements.end())
745748
{
746749
synopsis_line += " [\\fB--\\fP]";
747-
for (auto it = positional_subrange.begin(); it != positional_subrange.end(); ++it)
750+
for (auto it = pivot; it != synopsis_elements.end(); ++it)
748751
{
749752
synopsis_line += " " + it->option_str;
750753
}
@@ -766,8 +769,15 @@ class format_help_base : public format_base
766769
//!\brief Structure to store synopsis element information.
767770
struct synopsis_element
768771
{
769-
std::string option_str; //!< The formatted option string.
770-
bool is_positional{false}; //!< Whether it's a positional argument.
772+
//!\brief Kinds of options.
773+
enum class option_type : uint8_t
774+
{
775+
flag, //!< Option is a flag.
776+
option, //!< Option is a option with argument.
777+
positional //!< Option is a positional option.
778+
};
779+
std::string option_str; //!< The formatted option string.
780+
option_type type; //!< Type of the option.
771781
};
772782

773783
//!\brief Stores elements for automatic synopsis generation.
@@ -796,6 +806,7 @@ class format_help_base : public format_base
796806
* \param[in] type_str The type string for the option value.
797807
* \param[in] required Whether the option is required.
798808
* \param[in] is_list Whether it's a list of arguments.
809+
* \sa https://pubs.opengroup.org/onlinepubs/9699919799
799810
*/
800811
void store_synopsis_option(detail::id_pair const & id,
801812
std::string const & type_str,
@@ -818,20 +829,23 @@ class format_help_base : public format_base
818829
opt_str = opt_str + " [" + opt_str + "]...";
819830
}
820831

821-
synopsis_elements.push_back({opt_str, false});
832+
synopsis_elements.push_back({std::move(opt_str), synopsis_element::option_type::option});
822833
}
823834

824835
/*!\brief Stores flag information for synopsis generation.
825836
* \param[in] id A sharg::detail::id_pair encapsulating both short and long id.
837+
* \sa https://pubs.opengroup.org/onlinepubs/9699919799
826838
*/
827839
void store_synopsis_flag(detail::id_pair const & id)
828840
{
829-
synopsis_elements.push_back({prep_id_for_help(id, true), false});
841+
std::string flag_str = "[" + prep_id_for_help(id, true) + "]";
842+
synopsis_elements.push_back({std::move(flag_str), synopsis_element::option_type::flag});
830843
}
831844

832845
/*!\brief Stores positional argument information for synopsis generation.
833846
* \param[in] type_str The type string for the positional argument.
834847
* \param[in] is_list Whether it's a list of arguments.
848+
* \sa https://pubs.opengroup.org/onlinepubs/9699919799
835849
*/
836850
void store_synopsis_positional(std::string const & type_str, bool const is_list)
837851
{
@@ -840,7 +854,7 @@ class format_help_base : public format_base
840854
if (is_list)
841855
pos_str += "...";
842856

843-
synopsis_elements.push_back({pos_str, true});
857+
synopsis_elements.push_back({std::move(pos_str), synopsis_element::option_type::positional});
844858
}
845859

846860
/*!\brief Adds a function object to parser_set_up_calls **if** the annotation in `config` does not prevent it.

include/sharg/platform.hpp

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,85 @@
22
// SPDX-FileCopyrightText: 2016-2025, Knut Reinert & MPI für molekulare Genetik
33
// SPDX-License-Identifier: BSD-3-Clause
44

5-
#pragma once
6-
75
/*!\file
86
* \brief Provides platform and dependency checks.
97
* \author Svenja Mehringer <svenja.mehringer AT fu-berlin.de>
108
*/
119

10+
#pragma once
11+
12+
#include <version>
13+
14+
// ============================================================================
15+
// Compiler support general
16+
// ============================================================================
17+
18+
/*!\def SHARG_COMPILER_IS_GCC
19+
* \brief Whether the current compiler is GCC.
20+
* \details
21+
* __GNUC__ is also used to indicate the support for GNU compiler extensions. To detect the presence of the GCC
22+
* compiler, one has to rule out other compilers.
23+
*
24+
* \sa https://sourceforge.net/p/predef/wiki/Compilers
25+
*/
26+
#if defined(__GNUC__) && !defined(__llvm__) && !defined(__INTEL_COMPILER) && !defined(__INTEL_LLVM_COMPILER)
27+
# define SHARG_COMPILER_IS_GCC 1
28+
#else
29+
# define SHARG_COMPILER_IS_GCC 0
30+
#endif
31+
32+
// ============================================================================
33+
// Compiler support
34+
// ============================================================================
35+
36+
#if SHARG_COMPILER_IS_GCC && (__GNUC__ < 12)
37+
# error "Sharg requires at least GCC 12."
38+
#endif
39+
40+
// clang-format off
41+
#if defined(__INTEL_LLVM_COMPILER) && (__INTEL_LLVM_COMPILER < 20240000)
42+
# error "Sharg requires at least Intel OneAPI 2024."
43+
#endif
44+
// clang-format on
45+
46+
#if defined(__clang__) && defined(__clang_major__) && (__clang_major__ < 17)
47+
# error "Sharg requires at least Clang 17."
48+
#endif
49+
50+
// ============================================================================
51+
// Standard library support
52+
// ============================================================================
53+
54+
#if defined(_LIBCPP_VERSION) && (_LIBCPP_VERSION < 170000)
55+
# error "Sharg requires at least libc++ 17."
56+
#endif
57+
58+
#if defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 12)
59+
# error "Sharg requires at least libstdc++ 12."
60+
#endif
61+
1262
// ============================================================================
1363
// C++ standard and features
1464
// ============================================================================
1565

1666
// C++ standard [required]
1767
#ifdef __cplusplus
18-
static_assert(__cplusplus >= 201709L, "SHARG requires C++20, make sure that you have set -std=c++20.");
68+
# if (__cplusplus < 202100)
69+
# error "Sharg requires C++23, make sure that you have set -std=c++23."
70+
# endif
1971
#else
2072
# error "This is not a C++ compiler."
2173
#endif
2274

23-
#include <version>
24-
2575
// ============================================================================
2676
// Dependencies
2777
// ============================================================================
2878

29-
// SHARG [required]
79+
// Sharg [required]
3080
#if __has_include(<sharg/version.hpp>)
3181
# include <sharg/version.hpp>
3282
#else
33-
# error SHARG include directory not set correctly. Forgot to add -I ${INSTALLDIR}/include to your CXXFLAGS?
83+
# error "Sharg include directory not set correctly. Forgot to add -I ${INSTALLDIR}/include to your CXXFLAGS?"
3484
#endif
3585

3686
// ============================================================================

test/api_stability/1.1.1/0001-API-Update-TDL.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
From 7ed1d89ffe49487b0c9d2a25ab48a78d4b9fb43a Mon Sep 17 00:00:00 2001
1+
From 947ad6ee223e73c674f0e0a72c3c4ca43e21a7bc Mon Sep 17 00:00:00 2001
22
From: Simon Gene Gottlieb <simon@gottliebtfreitag.de>
33
Date: Thu, 5 Oct 2023 13:43:30 +0200
44
Subject: [PATCH 01/13] [API] Update TDL

test/api_stability/1.1.1/0002-API-Quoted-strings-and-paths.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
From e19583fdc827f80ee5feffc17161176a512bbdbb Mon Sep 17 00:00:00 2001
1+
From 2821481d732dfda7ac00ce9d3089053b482ed168 Mon Sep 17 00:00:00 2001
22
From: Enrico Seiler <enrico.seiler@hotmail.de>
33
Date: Mon, 5 Feb 2024 16:02:03 +0100
44
Subject: [PATCH 02/13] [API] Quoted strings and paths

test/api_stability/1.1.1/0003-NOAPI-Update-copyright.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
From 796bb41ed97fb796ef40fb8c2825e4bf3ca6317b Mon Sep 17 00:00:00 2001
1+
From fc0e69c7ca7314c714bd0eab7386e861fa34fb6a Mon Sep 17 00:00:00 2001
22
From: Enrico Seiler <enrico.seiler@hotmail.de>
33
Date: Wed, 7 Feb 2024 13:31:22 +0100
44
Subject: [PATCH 03/13] [NOAPI] Update copyright

0 commit comments

Comments
 (0)