Skip to content

Commit

Permalink
style: reformat (not all) files
Browse files Browse the repository at this point in the history
  • Loading branch information
ggabriel96 committed Feb 2, 2025
1 parent b8af589 commit 6f4910e
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 58 deletions.
21 changes: 10 additions & 11 deletions examples/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@
#include "experimental/all.hpp"

int main(int argc, char const *argv[]) {
auto p = DefaultProgram("pull", "1.0")
.Intro("Pull an image or a repository from a registry")
.Pos<"name", std::string>({.help = "The name of the image or repository to pull"})
.Opt<"platform", std::string>({.help = "Set platform if server is multi-platform capable"})
.Flg<"all-tags", "a">({.help = "Download all tagged images in the repository"})
.Flg<"disable-content-trust">({.help = "Skip image verification"})
.Flg<"quiet", "q">({.help = "Supress verbose output"})
;
auto p = DefaultProgram("pull", "1.0")
.Intro("Pull an image or a repository from a registry")
.Pos<"name", std::string>({.help = "The name of the image or repository to pull"})
.Opt<"platform", std::string>({.help = "Set platform if server is multi-platform capable"})
.Flg<"all-tags", "a">({.help = "Download all tagged images in the repository"})
.Flg<"disable-content-trust">({.help = "Skip image verification"})
.Flg<"quiet", "q">({.help = "Supress verbose output"});

// p.SetValue<"age">(28);
// auto age = p.GetValue<"name">();
// fmt::print("name: [{}]\n", age.value_or(std::string()));
// p.SetValue<"age">(28);
// auto age = p.GetValue<"name">();
// fmt::print("name: [{}]\n", age.value_or(std::string()));
}
14 changes: 7 additions & 7 deletions include/experimental/arg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ struct Arg {
std::string_view abbrev{};
std::string_view help{};
bool is_required = true;
// BuiltinVariant default_value{};
// BuiltinVariant implicit_value{};
// act::fn::Signature action_fn = act::fn::assign<std::string_view>;
// std::size_t gather_amount = 1;
// DefaultValueSetter default_setter = nullptr;
// BuiltinVariant default_value{};
// BuiltinVariant implicit_value{};
// act::fn::Signature action_fn = act::fn::assign<std::string_view>;
// std::size_t gather_amount = 1;
// DefaultValueSetter default_setter = nullptr;

constexpr bool has_abbrev() const noexcept { return !abbrev.empty(); }
// constexpr bool has_default() const noexcept { return default_value.index() != 0 || default_setter != nullptr; }
// constexpr bool has_implicit() const noexcept { return implicit_value.index() != 0; }
// constexpr bool has_default() const noexcept { return default_value.index() != 0 || default_setter != nullptr; }
// constexpr bool has_implicit() const noexcept { return implicit_value.index() != 0; }
constexpr bool is_positional() const noexcept { return type == ArgType::POS; }

std::string format_base_usage() const noexcept;
Expand Down
4 changes: 1 addition & 3 deletions include/experimental/fixed_string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ struct fixed_string {
}
}

constexpr operator std::string_view() const noexcept {
return std::string_view(data, N);
}
constexpr operator std::string_view() const noexcept { return std::string_view(data, N); }
};

#endif
8 changes: 5 additions & 3 deletions include/experimental/get_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ struct GetType : TypeResult<void> {};

// base case (type found)
template <fixed_string Needle, fixed_string... Haystack, typename NeedleType, typename... HaystackTypes>
struct GetType<Needle, StringList<Needle, Haystack...>, TypeList<NeedleType, HaystackTypes...>> : TypeResult<NeedleType> {};
struct GetType<Needle, StringList<Needle, Haystack...>, TypeList<NeedleType, HaystackTypes...>>
: TypeResult<NeedleType> {};

// recursion case (keep looking)
template <fixed_string Needle, fixed_string Other, fixed_string... Haystack, typename OtherType, typename... HaystackTypes>
template <fixed_string Needle, fixed_string Other, fixed_string... Haystack, typename OtherType,
typename... HaystackTypes>
struct GetType<Needle, StringList<Other, Haystack...>, TypeList<OtherType, HaystackTypes...>>
: GetType<Needle, StringList<Haystack...>, TypeList<HaystackTypes...>> {};
: GetType<Needle, StringList<Haystack...>, TypeList<HaystackTypes...>> {};

#endif
56 changes: 29 additions & 27 deletions include/experimental/program.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "experimental/fixed_string.hpp"
#include "experimental/get_type.hpp"

template<typename ...>
template <typename...>
struct Program;

template <fixed_string... Names, typename... Types>
Expand All @@ -22,7 +22,7 @@ struct Program<StringList<Names...>, TypeList<Types...>> {
std::string_view name{};
std::string_view version{};
std::string_view intro{};
std::array<Arg, sizeof... (Names)> args;
std::array<Arg, sizeof...(Names)> args;
std::size_t amount_pos = 0;

consteval Program() = default;
Expand All @@ -33,7 +33,7 @@ struct Program<StringList<Names...>, TypeList<Types...>> {
name = other.name;
version = other.version;
intro = other.intro;
std::copy_n(other.args.begin(), sizeof... (OtherNames), args.begin());
std::copy_n(other.args.begin(), sizeof...(OtherNames), args.begin());
}

consteval auto Intro(std::string_view intro) const noexcept {
Expand All @@ -45,12 +45,12 @@ struct Program<StringList<Names...>, TypeList<Types...>> {
template <fixed_string Name, typename T>
consteval auto Pos(ArgMeta meta) {
Program<StringList<Name, Names...>, TypeList<T, Types...>> new_program(*this);
new_program.args[sizeof... (Names) - 1] = Arg{
.type = ArgType::POS,
.name = Name,
.abbrev = "",
.help = meta.help,
.is_required = meta.is_required,
new_program.args[sizeof...(Names) - 1] = Arg{
.type = ArgType::POS,
.name = Name,
.abbrev = "",
.help = meta.help,
.is_required = meta.is_required,
};
new_program.amount_pos += 1;
std::sort(new_program.args.begin(), new_program.args.end());
Expand All @@ -60,29 +60,31 @@ struct Program<StringList<Names...>, TypeList<Types...>> {
template <fixed_string Name, fixed_string Abbrev, typename T>
consteval auto Opt(ArgMeta meta) {
Program<StringList<Name, Names...>, TypeList<T, Types...>> new_program(*this);
new_program.args[sizeof... (Names) - 1] = Arg{
.type = ArgType::OPT,
.name = Name,
.abbrev = Abbrev,
.help = meta.help,
.is_required = meta.is_required,
new_program.args[sizeof...(Names) - 1] = Arg{
.type = ArgType::OPT,
.name = Name,
.abbrev = Abbrev,
.help = meta.help,
.is_required = meta.is_required,
};
std::sort(new_program.args.begin(), new_program.args.end());
return new_program;
}

template <fixed_string Name, typename T>
consteval auto Opt(ArgMeta meta) { return Opt<Name, "", T>(meta); }
consteval auto Opt(ArgMeta meta) {
return Opt<Name, "", T>(meta);
}

template <fixed_string Name, fixed_string Abbrev = "">
consteval auto Flg(ArgMeta meta) {
Program<StringList<Name, Names...>, TypeList<bool, Types...>> new_program(*this);
new_program.args[sizeof... (Names) - 1] = Arg{
.type = ArgType::FLG,
.name = Name,
.abbrev = Abbrev,
.help = meta.help,
.is_required = meta.is_required,
new_program.args[sizeof...(Names) - 1] = Arg{
.type = ArgType::FLG,
.name = Name,
.abbrev = Abbrev,
.help = meta.help,
.is_required = meta.is_required,
};
std::sort(new_program.args.begin(), new_program.args.end());
return new_program;
Expand All @@ -109,11 +111,11 @@ struct Program<StringList<Names...>, TypeList<Types...>> {
consteval auto DefaultProgram(std::string_view name, std::string_view version = "") {
auto p = Program<StringList<"help">, TypeList<bool>>(name);
p.args[0] = Arg{
.type = ArgType::FLG,
.name = "help",
.abbrev = "h",
.help = "Display this information",
.is_required = false,
.type = ArgType::FLG,
.name = "help",
.abbrev = "h",
.help = "Display this information",
.is_required = false,
};
return p;
}
Expand Down
9 changes: 5 additions & 4 deletions include/experimental/string_list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@ struct InStringList<Needle, StringList<Other, Haystack...>> : InStringList<Needl
// +--------------------------------+

// base case (str not found)
template<int Idx, fixed_string, typename...>
template <int Idx, fixed_string, typename...>
struct IndexOfStr : std::integral_constant<int, -1> {};

// base case (str found)
template<int Idx, fixed_string Needle, fixed_string... Haystack>
template <int Idx, fixed_string Needle, fixed_string... Haystack>
struct IndexOfStr<Idx, Needle, StringList<Needle, Haystack...>> : std::integral_constant<int, Idx> {};

// recursive case (keep looking)
template<int Idx, fixed_string Needle, fixed_string Other, fixed_string... Haystack>
struct IndexOfStr<Idx, Needle, StringList<Other, Haystack...>> : IndexOfStr<Idx + 1, Needle, StringList<Haystack...>> {};
template <int Idx, fixed_string Needle, fixed_string Other, fixed_string... Haystack>
struct IndexOfStr<Idx, Needle, StringList<Other, Haystack...>> : IndexOfStr<Idx + 1, Needle, StringList<Haystack...>> {
};

#endif
6 changes: 3 additions & 3 deletions include/experimental/type_list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ struct TypeList;
// | IndexOfType |
// +-----------------------------------+

template<int, typename... Ts>
template <int, typename... Ts>
struct IndexOfType : std::integral_constant<int, -1> {};

template<int Idx, typename T, typename... Ts>
template <int Idx, typename T, typename... Ts>
struct IndexOfType<Idx, T, TypeList<T, Ts...>> : std::integral_constant<int, Idx> {};

template<int Idx, typename T, typename U, typename... Ts>
template <int Idx, typename T, typename U, typename... Ts>
struct IndexOfType<Idx, T, TypeList<U, Ts...>> : IndexOfType<Idx + 1, T, TypeList<Ts...>> {};

#endif

0 comments on commit 6f4910e

Please sign in to comment.