Something went wrong. Try again.
Charm-like tui library
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293const std = @import("std");const zli = @import("zli");const buds = @import("buds.zig");
pub fn main(init: std.process.Init) !void { try zli.run(init, .{ .description = "Hex cli", }, &.{ buds.group, .group("math", "examples with numbers", &.{ .func(add, "add two numbers"), .func(multiply, "multiply two numbers"), .func(@"mul-all", "multiply an array of numbers"), }), .func(optionals, "random params test"), });}
const Errors = error{ ErrorOne, ErrorTwo,};
fn add( init: std.process.Init, a: zli.param.Int("first-number", "a number", .{}), b: zli.param.Int("second-number", "value to add to first", .{}),) !void { var buffer: [256:0]u8 = @splat(0); const file = std.Io.File.stdout(); var f = file.writer(init.io, &buffer); const writer = &f.interface;
const value = try std.math.add(i128, a.value, b.value); try writer.print("{d}", .{value}); try writer.flush();}
fn multiply( init: std.process.Init, a: zli.param.Int("a", "first number", .{}), b: zli.param.Int("b", "second number", .{}),) !void { var buffer: [256:0]u8 = @splat(0); const file = std.Io.File.stdout(); var f = file.writer(init.io, &buffer); const writer = &f.interface;
const value = try std.math.mul(i128, a.value, b.value); try writer.print("{d}", .{value}); try writer.flush();}
fn @"mul-all"( init: std.process.Init, list: zli.param.Param([]f128, "numbers", "numbers to multiply together", .{}),) !void { var buffer: [256:0]u8 = @splat(0); const file = std.Io.File.stdout(); var f = file.writer(init.io, &buffer); const writer = &f.interface;
var number: f128 = 1; for (list.value) |num| number *= num;
try writer.print("{d}", .{number}); try writer.flush();}
fn optionals( init: std.process.Init, mandatory: zli.param.Int( "number", "This is a mandatory parameter and must be supplied in an arg", .{}, ), string: zli.param.String("string", "This is an optional parameter", .{ // this will be used if a value is not passed in the cli. .optional = .default("value"), }), nullable: zli.param.Param( ?[]const u8, "maybe-string", "This will actually return null if a value is not passed in", .{ .optional = .default(null) }, ),) Errors!void { _ = init; _ = mandatory; _ = string; _ = nullable;}