remove user.zig dependency on shell.zig
This commit is contained in:
parent
da727113e5
commit
2964c918cc
18
src/user.zig
18
src/user.zig
|
@ -1,5 +1,4 @@
|
|||
const std = @import("std");
|
||||
const shell = @import("shell.zig");
|
||||
|
||||
const Allocator = std.mem.Allocator;
|
||||
|
||||
|
@ -27,18 +26,26 @@ pub const User = struct {
|
|||
|
||||
// UserWriter accepts a naive User struct and returns a PackedUser
|
||||
pub const UserWriter = struct {
|
||||
allocator: Allocator,
|
||||
|
||||
pub fn init(allocator: Allocator) UserWriter {
|
||||
// shellIndexFnType is a signature for a function that accepts a shell
|
||||
// string and returns it's index in the global shell section. Passing a
|
||||
// function makes tests easier, and removes the Shell dependency of this
|
||||
// module.
|
||||
const shellIndexFnType = fn ([]const u8) ?u10;
|
||||
allocator: Allocator,
|
||||
shellIndexFn: shellIndexFnType,
|
||||
|
||||
pub fn init(allocator: Allocator, shellIndexFn: shellIndexFnType) UserWriter {
|
||||
return UserWriter{
|
||||
.allocator = allocator,
|
||||
.shellIndexFn = shellIndexFn,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn fromUser(user: User, shellw: shell.ShellWriter) !PackedUser {
|
||||
pub fn fromUser(self: *UserWriter, user: User) !PackedUser {
|
||||
var shell_here: u1 = undefined;
|
||||
var shell_len_or_place: u6 = undefined;
|
||||
if (shellw.getIndex(user.shell)) |idx| {
|
||||
if (self.shellIndexFn(user.shell)) |idx| {
|
||||
shell_here = false;
|
||||
shell_len_or_place = idx;
|
||||
} else {
|
||||
|
@ -58,7 +65,6 @@ pub const UserWriter = struct {
|
|||
.gecos_len = undefined,
|
||||
};
|
||||
|
||||
_ = shellw;
|
||||
return puser;
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue