Skip to content

Releases: prajwalch/yazap

v0.5.0

21 Jun 10:54
25416f7
Compare
Choose a tag to compare

Breaking Changes

flag Changes

  • Moved and Renamed boolean() to Arg.booleanOption().

  • Moved and Renamed argOne() to Arg.singleValueOption().

  • Moved and Renamed argN() to Arg.multiValuesOption() with slightly
    modified parameter order.

    Old

    fn(name: []const u8, short_name: ?u8, max_values: usize, description: ?[]const u8) Arg;

    New

    fn(name: []const u8, short_name: ?u8, description: ?[]const u8, max_values: usize) Arg;
  • Moved and Renamed option() to Arg.singleValueOptionWithValidValues() with
    slightly modified parameter order.

    Old

    fn(name: []const u8, short_name: ?u8, values: []const []const u8, description: ?[]const u8);

    New

    fn(name: []const u8, short_name: ?u8, description: ?[]const u8, values: []const []const u8);

Examples

Before:

const flag = yazap.flag

// -- snip --
try root.addArg(flag.boolean("bool", null, null));
try root.addArg(flag.argOne("one", null, null));
try root.addArg(flag.argN("many", null, 2, null));
try root.addArg(flag.option("opt", null, &[_][]const u8 {
    "opt1",
    "opt2",
}, null));
// -- snip --

After:

const Arg = yazap.Arg

// -- snip --
try root.addArg(Arg.booleanOption("bool", null, null));
try root.addArg(Arg.singleValueOption("one", null, null));
try root.addArg(Arg.multiValuesOption("many", null, null, 2));
try root.addArg(Arg.singleValueOptionWithValidValues("opt", null, null, &[_][]const u8 {
    "opt1",
    "opt2",
}));
// -- snip --

Command Changes

  • Renamed countArgs() to countPositionalArgs().
  • Renamed setSetting() to setProperty().
  • Renamed unsetSetting() to unsetProperty().
  • Renamed isSettingSet() to hasProperty().
  • Removed takesSingleValue() and takesNValues(), use new Arg.positional()
    instead.

Arg Changes

  • Renamed allowed_values to valid_values.
  • Renamed setAllowedValues() to setValidValues().
  • Renamed setSetting() to setProperty().
  • Renamed unsetSetting() to unsetProperty().
  • Renamed isSettingSet() to hasProperty().
  • Removed setShortNameFromName().
  • Removed setNameAsLongName().

ArgsContext Changes

  • Renamed ArgsContext to ArgMatches.
  • Renamed isPresent() to containsArg().
  • Renamed valueOf() to getSingleValue().
  • Renamed valuesOf() to getMultiValues().
  • Renamed subcommandContext() to subcommandMatches().

What's New

  • Introduced Arg.multiValuesOptionWithValidValues() API to support creating an argument that can take multiple arguments
    from pre-defined values.

  • Introduced Arg.positional() API, eliminating the need to set the .takes_positional_arg property for commands. This simplifies the
    process of creating positional arguments.

    Before

    var root = app.rootCommand();
    
    try root.takesSingleValue("ONE");
    try root.takesSingleValue("TWO");
    try root.takesSingleValue("THREE");
    root.setSetting(.takes_positional_arg);

    After

    const Arg = yazap.Arg;
    
    var root = app.rootCommand();
    
    // Arg.positional(name: []const u8, description: ?[]const u8, index: ?usize)
    
    // Order dependent
    try root.addArg(Arg.positional("ONE", null, null));
    try root.addArg(Arg.positional("TWO", null, null));
    try root.addArg(Arg.positional("THREE", null, null));
    
    // Equivalent but order independent
    try root.addArg(Arg.positional("THREE", null, 3));
    try root.addArg(Arg.positional("TWO", null, 2));
    try root.addArg(Arg.positional("ONE", null, 1));
  • Enhanced documentation for App.* API with detailed explanations and examples.

  • Enhanced documentation for Arg.* API with detailed explanations and examples.

  • Enhanced documentation for Command.* API with detailed explanations and examples.

Internal Changes

  • Removed enable_help property for commands, making -h and --help options
    always available for both the root command and subcommands.

v0.4.0

25 Oct 17:43
Compare
Choose a tag to compare

What's new:

  • Added Yazap.displayHelp and Yazap.displaySubcommandHelp to manually display root command help and provided subcommand help respectively
  • Added Command.addArgs and Command.addSubcommands

Breaking changes:

  • Command.takesValue, Command.argRequired, Command.subcommandRequired,
    Arg.takesValue, Arg.takesMultipleValues and Arg.allowedEmptyValue is removed and now you have to use applySetting and removeSetting to set and unset setting
    Ex:
    var app = Yazap.init(allocator, "app", null);
    defer app.deinit();
    
    var cmd = app.rootCommand();
    cmd.applySetting(.takes_value);

Fixes:

  • Fixed v0.10.0 optional specifier error messaged (#6)
  • Now parsing will be stop after encountering help option (-h or --help)

v0.3.0

23 Sep 07:25
Compare
Choose a tag to compare

What's new:

  • Added new Yazap as a main entry point for library. (b3a78ad)

    Now you have to use Yazap.init to initialize the library and Yazap.deinit to deinitilize all the structures at once. Previously you had to deinitilize the two structures (Command and ArgsContext which is previously returned by the Command.parseProcess and Command.parseFrom) by yourself.

  • Auto help text generation

    Now you don't need to defined -h, --help flag and handle it manually. yazap can now build and display help text dynamically based on provided arguments and their settings.

    Note: For now help will be displayed when -h, --help is provided but not on error. Once help will be displayed all the structures will be deinitilize and app will exit gracefully.

  • Added Arg.description and its Arg.setDescription setter

Breaking changes:

  • Command.parseFrom and Command.parseProcess is moved to Yazap
  • Command.about is renamed to Command.description
  • Command.newWithHelpTxt is renamed to Command.newWithDescription
  • Now flag.* functions takes a description of type ?[]const u8 as a last parameter

Fixes:

  • Thread panic error/Incorrect or an unexpected error message to be logged when an error used to occur when parsing subcommand's argument and trying to log error using root command error trace. (4c1f7de)
  • Value outside of Arg.allowed_values to be consumed without verifying it. (dcb7518)

v0.2.1

04 Sep 20:24
Compare
Choose a tag to compare

Fixes:

  • Fixed CommandArgumentNotProvided error when argRequired is set to false (#4)
  • Fixed an error message that shows parent command name instead of sub-command when CommandArgumentNotProvided error is returned from sub-command parser (#4)

v0.2.0 release!

01 Sep 14:39
Compare
Choose a tag to compare

What's new:

  • Added new Command.takesValue setter (f6ca476)
  • Added new Arg.takesMultipleValues API which allows Arg to take unknown number of values (f5e6512)

Internal changes:

  • fix(Parser): Set ErrorContext.setErr(err) when error is captured on else (98aee00)
  • refactor(Parser): Add a function to verify and append the value (c734d0c)
  • fix(Parser): Use a pointer capture instead of value capture (7caff04)

v0.1.0

28 Aug 09:38
efea318
Compare
Choose a tag to compare

Features

  • Flags

    • boolean/no argument flag (-f, --flag)

    • single argument flag (-f, --flag <VALUE>)

    • multi argument flag (-f, --flag <VALUES>)

      Note: You have to explicitly set the number of arguments for it

    • single argument flag with options (-f, --flag <A | B | C>)

    • Support passing value using space -f value
      no space -fvalue and using = (-f=value)

    • Support chaining multiple short flags

      • -xy where both x and y does not take value
      • -xyz=value
    • Support for specifying flag multiple times (-x a -x b -x c)

  • Subcommand

    • app bool-cmd
    • app single-arg-cmd <ARG>
    • app multi-arg-cmd <ARG1> <ARG2> <ARGS3...>
    • app flag-cmd [flags]
    • app arg-and-flag-cmd <ARG> [FLAGS]
    • Nested subcommand
  • Defining custom Argument