00JCIV00 / cova

Commands, Options, Values, Arguments. A simple yet robust cross-platform command line argument parsing library for Zig.
https://00jciv00.github.io/cova/
MIT License
110 stars 5 forks source link

Revamp UsageHelpConfig to DefaultArgsConfig #62

Open 00JCIV00 opened 2 months ago

00JCIV00 commented 2 months ago

Currently, the UsageHelpConfig works under the assumption that library users will always want to either use both Usage and Help or neither, but not one or the other. It's also only limited to those two Arguments.

This new API would solve both of these issues:

  1. Allow library users to choose exactly which Default Arguments they'd like to implement.
  2. Create an API that's flexible to additional Default Arguments in the future w/o causing breaking changes. (For example, adding Version alongside Usage and Help).

DefaultArgsConfig Example:

        /// Config for auto-generating Default Commands & Options during Initialization.
        pub const DefaultArgsConfig = struct{
            /// Add selected Default Commands to this Command and its sub-Commands.
            add_def_cmds: ?[]const DefaultArgKinds = &.{ .usage, .help, .version },
            /// Add selected Default Options to this Command and its sub-Commands.
            add_def_opts: ?[]const DefaultArgKinds = &.{ .usage, .help, .version },
            /// Set a name format for the Usage Options inner Value.
            /// This only takes effect if `add_def_opts` is not null or empty.
            /// Must support the following format types in this order:
            /// 1. String (Default Option Name)
            def_val_name: []const u8 = "{s}_flag",
            /// Set a description format for the Usage Command & Option.
            /// Must support the following format types in this order:
            /// 1. String (Command Name)
            /// 2. String (Default Command Name)
            def_desc_fmt: []const u8 = "Show the '{s}' {s} display.",
            /// Add a Command Group for Default Commands.
            /// Note, this will only take effect if `add_def_cmds` is not null or empty.
            add_def_cmd_group: AddDefaultGroup = .AddIfOthers,
            /// Add an Option Group for Default Options.
            /// Note, this will only take effect if `add_def_opts` is not null or empty.
            add_def_opt_group: AddHelpGroup = .AddIfOthers,
            /// Default Argument Group Name.
            def_arg_group_name: []const u8 = "INFO",

            /// Determine behavior for adding a Default Argument Group.
            pub const AddDefaultGroup = enum{
                /// Add if there are other Argument Groups.
                AddIfOthers,
                /// Add regardless of other Argument Groups.
                Add,
                /// Do not add.
                DoNotAdd,
            };

            /// Default Argument Kinds
            pub const DefaultArgKinds = enum {
                usage,
                help,
                version,
            };
        };