getCurl implementation. Note Linux not tested
This commit is contained in:
parent
c5ffd71eed
commit
113fb5e75c
|
@ -1,3 +1,4 @@
|
|||
const builtin = @import("builtin");
|
||||
const std = @import("std");
|
||||
const zfetch = @import("zfetch");
|
||||
const crypt = @import("crypt.zig");
|
||||
|
@ -139,10 +140,59 @@ fn get(allocator: std.mem.Allocator) ![]const u8 {
|
|||
}
|
||||
|
||||
fn getCurl(allocator: std.mem.Allocator, curl_path: []const u8) ![]const u8 {
|
||||
_ = allocator;
|
||||
_ = curl_path;
|
||||
return "hello";
|
||||
std.log.debug("curl path: {s}", .{curl_path});
|
||||
const result = os: {
|
||||
if (builtin.os.tag == .linux) {
|
||||
const curl_cmd = try std.fmt.allocPrint(allocator, "{s} -s {s}", .{ curl_path, clipboard_url });
|
||||
defer allocator.free(curl_cmd);
|
||||
break :os try execLinux(allocator, curl_cmd);
|
||||
} else if (builtin.os.tag == .windows) {
|
||||
break :os try std.ChildProcess.exec(.{
|
||||
.allocator = allocator,
|
||||
.argv = &[_][]const u8{
|
||||
curl_path, // TODO: use Comspec
|
||||
"-s",
|
||||
clipboard_url,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
return error.OsUnsupported;
|
||||
}
|
||||
};
|
||||
try std.io.getStdErr().writer().writeAll(result.stderr);
|
||||
switch (result.term) {
|
||||
.Exited => |code| if (code == 0) {
|
||||
return result.stdout;
|
||||
} else return error.NonZeroExit,
|
||||
.Signal => return error.FailedWithSignal,
|
||||
.Stopped => return error.WasStopped,
|
||||
.Unknown => return error.Failed,
|
||||
}
|
||||
}
|
||||
|
||||
fn execLinux(allocator: std.mem.Allocator, cmd: []const u8) !std.ChildProcess.ExecResult {
|
||||
return std.ChildProcess.exec(.{
|
||||
.allocator = allocator,
|
||||
.argv = &[_][]const u8{
|
||||
"/usr/bin/env",
|
||||
"sh",
|
||||
"-c",
|
||||
cmd,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// Potentially useful code, but no longer necessary
|
||||
// fn execWindows(allocator: std.mem.Allocator, cmd: []const u8) !std.ChildProcess.ExecResult {
|
||||
// return std.ChildProcess.exec(.{
|
||||
// .allocator = allocator,
|
||||
// .argv = &[_][]const u8{
|
||||
// "c:\\windows\\system32\\cmd.exe", // TODO: use Comspec
|
||||
// "/c",
|
||||
// cmd,
|
||||
// },
|
||||
// });
|
||||
// }
|
||||
|
||||
fn post(allocator: std.mem.Allocator, data: []const u8) !void {
|
||||
// TODO: Windows
|
||||
|
|
Loading…
Reference in New Issue
Block a user