mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
config: track the location of CLI argument errors
This commit is contained in:
@ -856,6 +856,34 @@ test "parseIntoField: tagged union missing tag" {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// An iterator that considers its location to be CLI args. It
|
||||||
|
/// iterates through an underlying iterator and increments a counter
|
||||||
|
/// to track the current CLI arg index.
|
||||||
|
pub fn ArgsIterator(comptime Iterator: type) type {
|
||||||
|
return struct {
|
||||||
|
const Self = @This();
|
||||||
|
|
||||||
|
/// The underlying args iterator.
|
||||||
|
iterator: Iterator,
|
||||||
|
|
||||||
|
/// Our current index into the iterator. This is 1-indexed.
|
||||||
|
/// The 0 value is used to indicate that we haven't read any
|
||||||
|
/// values yet.
|
||||||
|
index: usize = 0,
|
||||||
|
|
||||||
|
pub fn next(self: *Self) ?[]const u8 {
|
||||||
|
const value = self.iterator.next() orelse return null;
|
||||||
|
self.index += 1;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns a location for a diagnostic message.
|
||||||
|
pub fn location(self: *const Self) ?Diagnostic.Location {
|
||||||
|
return .{ .cli = self.index };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns an iterator (implements "next") that reads CLI args by line.
|
/// Returns an iterator (implements "next") that reads CLI args by line.
|
||||||
/// Each CLI arg is expected to be a single line. This is used to implement
|
/// Each CLI arg is expected to be a single line. This is used to implement
|
||||||
/// configuration files.
|
/// configuration files.
|
||||||
@ -946,8 +974,7 @@ pub fn LineIterator(comptime ReaderType: type) type {
|
|||||||
return self.entry[0 .. buf.len + 2];
|
return self.entry[0 .. buf.len + 2];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Modify the diagnostic so it includes richer context about
|
/// Returns a location for a diagnostic message.
|
||||||
/// the location of the error.
|
|
||||||
pub fn location(self: *const Self) ?Diagnostic.Location {
|
pub fn location(self: *const Self) ?Diagnostic.Location {
|
||||||
// If we have no filepath then we have no location.
|
// If we have no filepath then we have no location.
|
||||||
if (self.filepath.len == 0) return null;
|
if (self.filepath.len == 0) return null;
|
||||||
|
@ -2372,7 +2372,11 @@ pub fn loadCliArgs(self: *Config, alloc_gpa: Allocator) !void {
|
|||||||
if (iter.next()) |argv0| log.debug("skipping argv0 value={s}", .{argv0});
|
if (iter.next()) |argv0| log.debug("skipping argv0 value={s}", .{argv0});
|
||||||
|
|
||||||
// Parse the config from the CLI args
|
// Parse the config from the CLI args
|
||||||
try self.loadIter(alloc_gpa, &iter);
|
{
|
||||||
|
const ArgsIter = cli.args.ArgsIterator(@TypeOf(iter));
|
||||||
|
var args_iter: ArgsIter = .{ .iterator = iter };
|
||||||
|
try self.loadIter(alloc_gpa, &args_iter);
|
||||||
|
}
|
||||||
|
|
||||||
// If we are not loading the default files, then we need to
|
// If we are not loading the default files, then we need to
|
||||||
// replay the steps up to this point so that we can rebuild
|
// replay the steps up to this point so that we can rebuild
|
||||||
|
Reference in New Issue
Block a user