diff --git a/README.md b/README.md index ff24697..4e9d325 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,6 @@ var app = &cli.App{ .command = cli.Command{ .name = "short", .options = &.{ &host, &port }, - .description = cli.Description{ .one_line = "a short example" }, .target = cli.CommandTarget{ .action = cli.CommandAction{ .exec = run_server }, }, diff --git a/examples/short.zig b/examples/short.zig index 3a393ce..095408d 100644 --- a/examples/short.zig +++ b/examples/short.zig @@ -24,7 +24,6 @@ var app = &cli.App{ .command = cli.Command{ .name = "short", .options = &.{ &host, &port }, - .description = cli.Description{ .one_line = "a short example" }, .target = cli.CommandTarget{ .action = cli.CommandAction{ .exec = run_server }, }, diff --git a/examples/simple.zig b/examples/simple.zig index 8e7661c..7c852ed 100644 --- a/examples/simple.zig +++ b/examples/simple.zig @@ -73,9 +73,6 @@ var sub1 = cli.Command{ var sub2 = cli.Command{ .name = "sub2", - .description = cli.Description{ - .one_line = "sub2 help", - }, .target = cli.CommandTarget{ .action = cli.CommandAction{ .exec = run_sub2, diff --git a/examples/standalone/src/main.zig b/examples/standalone/src/main.zig index dfa51b1..095408d 100644 --- a/examples/standalone/src/main.zig +++ b/examples/standalone/src/main.zig @@ -8,6 +8,7 @@ var config = struct { host: []const u8 = "localhost", port: u16 = undefined, }{}; + var host = cli.Option{ .long_name = "host", .help = "host to listen on", @@ -23,11 +24,8 @@ var app = &cli.App{ .command = cli.Command{ .name = "short", .options = &.{ &host, &port }, - .description = cli.Description{ .one_line = "a short example" }, .target = cli.CommandTarget{ - .action = cli.CommandAction{ - .exec = run_server, - }, + .action = cli.CommandAction{ .exec = run_server }, }, }, }; diff --git a/src/command.zig b/src/command.zig index c4e117e..b15635d 100644 --- a/src/command.zig +++ b/src/command.zig @@ -29,7 +29,7 @@ pub const HelpConfig = struct { pub const Command = struct { name: []const u8, - description: Description, + description: ?Description = null, options: ?[]const *Option = null, target: CommandTarget, }; diff --git a/src/help.zig b/src/help.zig index be522a7..b1c0aaa 100644 --- a/src/help.zig +++ b/src/help.zig @@ -73,9 +73,11 @@ const HelpPrinter = struct { self.printer.printNewLine(); self.printer.printColor(color_clear); - self.printer.format("\n{s}\n", .{cmd.description.one_line}); - if (cmd.description.detailed) |det| { - self.printer.format("\n{s}\n", .{det}); + if (cmd.description) |desc| { + self.printer.format("\n{s}\n", .{desc.one_line}); + if (desc.detailed) |det| { + self.printer.format("\n{s}\n", .{det}); + } } switch (cmd.target) { @@ -107,13 +109,16 @@ const HelpPrinter = struct { self.printer.printColor(self.help_config.color_option); self.printer.format(" {s}", .{sc.name}); self.printer.printColor(color_clear); - var i: usize = 0; - while (i < cmd_column_width - sc.name.len) { - self.printer.write(" "); - i += 1; - } + if (sc.description) |desc| { + var i: usize = 0; + while (i < cmd_column_width - sc.name.len) { + self.printer.write(" "); + i += 1; + } - self.printer.format("{s}\n", .{sc.description.one_line}); + self.printer.format("{s}", .{desc.one_line}); + } + self.printer.printNewLine(); } }, }