Skip to content

Commit 3f90249

Browse files
committed
Hide logging behind verbose flag
1 parent 71395a7 commit 3f90249

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/main.zig

+11-5
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const Configuration = struct {
4949
check_format: ?bool = null,
5050
enforce_const_pointers: ?bool = null,
5151
include_gitignored: ?bool = null,
52+
verbose: ?bool = null,
5253
exclude: ?[][]const u8 = null,
5354
include: ?[][]const u8 = null,
5455

@@ -89,6 +90,9 @@ fn show_help() !void {
8990
\\ to view this help message again: ziglint help
9091
\\
9192
\\options:
93+
\\ --verbose
94+
\\ print more information about what ziglint is doing
95+
\\
9296
\\ --max-line-length <u32>
9397
\\ set the maximum length of a line of code
9498
\\
@@ -193,6 +197,8 @@ pub fn main() anyerror!void {
193197
switches.enforce_const_pointers = true;
194198
} else if (std.mem.eql(u8, switch_name, "include-gitignored")) {
195199
switches.include_gitignored = true;
200+
} else if (std.mem.eql(u8, switch_name, "verbose")) {
201+
switches.verbose = true;
196202
} else if (is_include or is_exclude) {
197203
args_idx += 1;
198204
if (args_idx >= args.len) {
@@ -240,7 +246,7 @@ pub fn main() anyerror!void {
240246
const files = if (cmd_line_files.items.len > 0) cmd_line_files.items else &[_][]const u8{"."};
241247
var fault_count: u64 = 0;
242248
for (files) |file| {
243-
var config_file_parsed = try get_config(file, arena_allocator);
249+
var config_file_parsed = try get_config(file, arena_allocator, switches.verbose orelse false);
244250
var config = switches;
245251

246252
if (config_file_parsed) |c| {
@@ -264,7 +270,7 @@ pub fn main() anyerror!void {
264270
if (config.include_gitignored != false) {
265271
const gitignore_path = try find_file(arena_allocator, file, ".gitignore");
266272
if (gitignore_path) |path| {
267-
try stderr_print("using Gitignore {s}", .{path});
273+
if (config.verbose orelse false) try stderr_print("using Gitignore {s}", .{path});
268274

269275
gitignore_text = try std.fs.cwd().readFileAlloc(arena_allocator, path, MAX_CONFIG_BYTES);
270276
try ignore_tracker.parse_gitignore(gitignore_text.?);
@@ -283,12 +289,12 @@ pub fn main() anyerror!void {
283289
}
284290

285291
// Creates a Configuration object for the given file based on the nearest ziglintrc file.
286-
fn get_config(file_name: []const u8, alloc: std.mem.Allocator) !?std.json.Parsed(Configuration) {
292+
fn get_config(file_name: []const u8, alloc: std.mem.Allocator, verbose: bool) !?std.json.Parsed(Configuration) {
287293
const ziglintrc_path = try find_file(alloc, file_name, "ziglint.json");
288294
if (ziglintrc_path) |path| {
289295
defer alloc.free(path);
290296

291-
try stderr_print("using config file {s}", .{path});
297+
if (verbose) try stderr_print("using config file {s}", .{path});
292298
const config_raw = try std.fs.cwd().readFileAlloc(alloc, path, MAX_CONFIG_BYTES);
293299
const cfg = std.json.parseFromSlice(Configuration, alloc, config_raw, .{}) catch |err| err_handle_blk: {
294300
switch (err) {
@@ -312,7 +318,7 @@ fn get_config(file_name: []const u8, alloc: std.mem.Allocator) !?std.json.Parsed
312318
if (cfg != null) return cfg;
313319
}
314320

315-
try stderr_print("warning: no valid ziglint.json found! using default configuration.", .{});
321+
if (verbose) try stderr_print("warning: no valid ziglint.json found! using default configuration.", .{});
316322
return null;
317323
}
318324

0 commit comments

Comments
 (0)