lib/pluck/src/cli/codes.zig
daab053ee43316e1809a84551d573ddd1e5bf3d2
1 const toplevel = @import("../root.zig").toplevel;
2 const QueryResult = toplevel.QueryResult;
3
4 pub const ExitCode = enum(u8) {
5 success = 0,
6 @"error" = 1,
7 partial_results = 2,
8
9 pub fn fromQueryResult(result: *const QueryResult) ExitCode {
10 if (result.program_error) return .@"error";
11 if (result.limit_reason != null) return .partial_results;
12 if (result.outcomes.len == 0) return .@"error";
13 return .success;
14 }
15
16 pub fn combine(a: ExitCode, b: ExitCode) ExitCode {
17 if (a == .@"error" or b == .@"error") return .@"error";
18 if (a == .partial_results or b == .partial_results) return .partial_results;
19 return .success;
20 }
21 };