Releases: prajwalch/yazap
v0.6.2
v0.6.1
v0.6.0
What's New
- Added new
Arg.setValuePlaceholder()
to display option's value placeholder in help message. For e.x.:-t, --time=<SECS>
. - Added new
.help_on_empty_args
property for a command which, when set, a help message is automatically displayed when arguments are not provided.
Before:
if (!matches.containsArgs()) {
try app.displayHelp();
return;
}
if (matches.subcommandMatches("update")) |update_cmd_matches| {
if (!update_cmd_matches.containsArgs()) {
try app.displaySubcommandHelp();
return;
}
}
After:
var app = App.init(allocator, "myls", "My custom ls");
defer app.deinit();
var myls = app.rootCommand();
myls.setProperty(.help_on_empty_args);
var update_cmd = app.createCommand("update", "Update the app or check for new updates");
update_cmd.setProperty(.help_on_empty_args);
try myls.addSubcommand(update_cmd);
const matches = try myls.parseProcess();
// --snip--
Note that App.displayHelp()
and App.displaySubcommandHelp()
are still available.
- Improved error messages.
- Polished help message.
What's Changed
App.parseProcess()
andApp.parseFrom()
now returnsArgMatches
directly instead of*const ArgMatches
.- Add
const
qualifier inCommand.addArgs
andCommand.addSubcommands
. By @monomycelium in #21 - Fix:
Arg.multiValuesOption
behavior when single value is provided by @fardragon in #26 - Fix: compiler crash during
zig build test
by @fardragon in 8f53fcb - Fix: subcommands with no values will never match #23. With this change,
ArgMatches.subcommandMatches()
now returns empty matches for any subcommand that doesn't take argument. - Fix: disable printing error messages during test.
Internal Improvements
- The parser implementation has been polished to make it easier to contribute by adding inline comments where necessary.
- Error handling has been enhanced.
- Improved the help message writer's implementation.
- Overall documentation is improved.
New Contributors
- @monomycelium made their first contribution in #21
- @fardragon made their first contribution in #26
Full Changelog: v0.5.1...v0.6.0
v0.5.1
A compatible update for zig v0.12.0
, v0.12.1
and v0.13.0
.
Fix
getOutputDocs
was renamed togetEmittedDocs
by @karlseguin in #13- Latest zig requires immutable
var
s to beconst
by @karlseguin in #15 std.os.WriteError
->std.posix.WriteError
by @cdmistman in #19- Minor fix for code example by @higuoxing in #5
What's Changed
New Contributors
- @karlseguin made their first contribution in #13
- @KNnut made their first contribution in #16
- @dasimmet made their first contribution in #17
- @joshua-software-dev made their first contribution in #18
- @cdmistman made their first contribution in #19
- @higuoxing made their first contribution in #5
v0.5.0
Breaking Changes
flag
Changes
-
Moved and Renamed
boolean()
toArg.booleanOption()
. -
Moved and Renamed
argOne()
toArg.singleValueOption()
. -
Moved and Renamed
argN()
toArg.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()
toArg.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()
tocountPositionalArgs()
. - Renamed
setSetting()
tosetProperty()
. - Renamed
unsetSetting()
tounsetProperty()
. - Renamed
isSettingSet()
tohasProperty()
. - Removed
takesSingleValue()
andtakesNValues()
, use newArg.positional()
instead.
Arg
Changes
- Renamed
allowed_values
tovalid_values
. - Renamed
setAllowedValues()
tosetValidValues()
. - Renamed
setSetting()
tosetProperty()
. - Renamed
unsetSetting()
tounsetProperty()
. - Renamed
isSettingSet()
tohasProperty()
. - Removed
setShortNameFromName()
. - Removed
setNameAsLongName()
.
ArgsContext
Changes
- Renamed
ArgsContext
toArgMatches
. - Renamed
isPresent()
tocontainsArg()
. - Renamed
valueOf()
togetSingleValue()
. - Renamed
valuesOf()
togetMultiValues()
. - Renamed
subcommandContext()
tosubcommandMatches()
.
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
What's new:
- Added
Yazap.displayHelp
andYazap.displaySubcommandHelp
to manually display root command help and provided subcommand help respectively - Added
Command.addArgs
andCommand.addSubcommands
Breaking changes:
Command.takesValue
,Command.argRequired
,Command.subcommandRequired
,
Arg.takesValue
,Arg.takesMultipleValues
andArg.allowedEmptyValue
is removed and now you have to useapplySetting
andremoveSetting
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
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
andArgsContext
which is previously returned by theCommand.parseProcess
andCommand.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 itsArg.setDescription
setter
Breaking changes:
Command.parseFrom
andCommand.parseProcess
is moved toYazap
Command.about
is renamed toCommand.description
Command.newWithHelpTxt
is renamed toCommand.newWithDescription
- Now
flag.*
functions takes adescription
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
v0.2.0 release!
v0.1.0
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 bothx
andy
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