M cmd/docker-credential-himitsu/erase.ha => cmd/docker-credential-himitsu/erase.ha +1 -3
@@ 5,9 5,7 @@ use net;
use os;
use strings;
-fn erase() void = {
- const hi = client::connect()!;
- defer net::close(hi)!;
+fn erase(hi: net::socket) void = {
const url = strings::fromutf8(bufio::scanline(os::stdin)! as []u8);
const query = query::query {
items = [
M cmd/docker-credential-himitsu/get.ha => cmd/docker-credential-himitsu/get.ha +1 -3
@@ 7,9 7,7 @@ use os;
use shlex;
use strings;
-fn get() void = {
- const hi = client::connect()!;
- defer net::close(hi)!;
+fn get(hi: net::socket) void = {
const url = strings::fromutf8(bufio::scanline(os::stdin)! as []u8);
const query = query::query {
items = [
M cmd/docker-credential-himitsu/list.ha => cmd/docker-credential-himitsu/list.ha +1 -3
@@ 6,9 6,7 @@ use os;
use shlex;
use strings;
-fn list() void = {
- const hi = client::connect()!;
- defer net::close(hi)!;
+fn list(hi: net::socket) void = {
const query = query::query {
items = [
query::pair { key = "proto", value = "docker", private = false, optional = false},
M cmd/docker-credential-himitsu/main.ha => cmd/docker-credential-himitsu/main.ha +21 -6
@@ 1,17 1,32 @@
+use fmt;
+use himitsu::client;
+use net;
use os;
export fn main() void = {
- assert(len(os::args) == 2);
+ if (len(os::args) != 2) {
+ fmt::fatalf("Usage: {} <store|get|erase|list>", os::args[0]);
+ };
+
+ const sock = match (client::connect()) {
+ case let s: net::socket =>
+ yield s;
+ case let err: client::error =>
+ fmt::fatalf("Cannot connect to himitsud: {}", client::strerror(err));
+ };
+ defer net::close(sock)!;
+
switch (os::args[1]) {
case "store" =>
- store();
+ store(sock);
case "get" =>
- get();
+ get(sock);
case "erase" =>
- erase();
+ erase(sock);
case "list" =>
- list();
+ list(sock);
case =>
- assert(false);
+ net::close(sock)!;
+ fmt::fatalf("Usage: {} <store|get|erase|list>", os::args[0]);
};
};
M cmd/docker-credential-himitsu/store.ha => cmd/docker-credential-himitsu/store.ha +1 -3
@@ 4,9 4,7 @@ use himitsu::query;
use net;
use os;
-fn store() void = {
- const hi = client::connect()!;
- defer net::close(hi)!;
+fn store(hi: net::socket) void = {
const json = json::load(os::stdin)! as json::object;
defer json::finish(json);
const url = *(json::get(&json, "ServerURL") as *json::value) as str;