Skip to content

Commit

Permalink
Make command description optional
Browse files Browse the repository at this point in the history
  • Loading branch information
sam701 committed Nov 22, 2023
1 parent 365050a commit e32f745
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 19 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
},
Expand Down
1 change: 0 additions & 1 deletion examples/short.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
},
Expand Down
3 changes: 0 additions & 3 deletions examples/simple.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 2 additions & 4 deletions examples/standalone/src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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 },
},
},
};
Expand Down
2 changes: 1 addition & 1 deletion src/command.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
23 changes: 14 additions & 9 deletions src/help.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
}
},
}
Expand Down

0 comments on commit e32f745

Please sign in to comment.