~sircmpwn/himitsu-devel

himitsu::client: Add `quit` operation v1 APPLIED

Hugo Osvaldo Barrera <hugo@barrera.io>
Hugo Osvaldo Barrera: 2
 himitsu::client: Add `quit` operation
 cmd/hiq: Reuse `operation` for himitsu::client

 2 files changed, 14 insertions(+), 18 deletions(-)
Thanks!

To git@git.sr.ht:~sircmpwn/himitsu
   c7d4942..2de1773  master -> master
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/himitsu-devel/patches/33571/mbox | git am -3
Learn more about email & git

[PATCH 1/2] himitsu::client: Add `quit` operation Export this patch

Hugo Osvaldo Barrera <hugo@barrera.io>
---
 himitsu/client/client.ha | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/himitsu/client/client.ha b/himitsu/client/client.ha
index 7b593b4..c307b95 100644
--- a/himitsu/client/client.ha
+++ b/himitsu/client/client.ha
@@ -16,6 +16,7 @@ export type operation = enum uint {
	QUERY,
	ADD,
	DEL,
	QUIT,
};

// Flags for query operations.
@@ -76,6 +77,8 @@ export fn query(
		fmt::fprint(&buf, "add")!;
	case operation::DEL =>
		fmt::fprint(&buf, "del")!;
	case operation::QUIT =>
		fmt::fprint(&buf, "quit")!;
	};

	if (flags & flags::DECRYPT != 0) {
-- 
2.37.0

[PATCH 2/2] cmd/hiq: Reuse `operation` for himitsu::client Export this patch

Hugo Osvaldo Barrera <hugo@barrera.io>
---
 cmd/hiq/main.ha | 29 +++++++++++------------------
 1 file changed, 11 insertions(+), 18 deletions(-)

diff --git a/cmd/hiq/main.ha b/cmd/hiq/main.ha
index cf72e52..90f401e 100644
--- a/cmd/hiq/main.ha
+++ b/cmd/hiq/main.ha
@@ -19,13 +19,6 @@ type flag = enum uint {
	DECRYPT = 1 << 1,
};

type operation = enum uint {
	QUERY,
	ADD,
	DEL,
	QUIT,
};

fn write_item(
	out: io::handle,
	items: str,
@@ -61,22 +54,22 @@ export fn main() void = {
	const cmd = getopt::parse(os::args, usage...);
	defer getopt::finish(&cmd);

	let op = operation::QUERY;
	let op = client::operation::QUERY;
	let flags: flag = 0, field = "";
	for (let i = 0z; i < len(cmd.opts); i += 1) {
		switch (cmd.opts[i].0) {
		case '1' =>
			flags |= flag::ONE;
		case 'a' =>
			op = operation::ADD;
			op = client::operation::ADD;
		case 'd' =>
			flags |= flag::DECRYPT;
		case 'D' =>
			op = operation::DEL;
			op = client::operation::DEL;
		case 'F' =>
			field = cmd.opts[i].1;
		case 'Q' =>
			op = operation::QUIT;
			op = client::operation::QUIT;
		};
	};

@@ -93,7 +86,7 @@ export fn main() void = {
	};
	defer io::close(conn)!;

	if (op == operation::ADD && len(cmd.args) == 0) {
	if (op == client::operation::ADD && len(cmd.args) == 0) {
		if (tty::isatty(os::stderr) && tty::isatty(os::stdin_file)) {
			fmt::errorln("Enter new keys, one per line, then press ^d:")!;
		};
@@ -113,7 +106,7 @@ export fn main() void = {
				defer strings::freeall(query);
				free(line);

				send(conn, operation::ADD, flags, field, query);
				send(conn, client::operation::ADD, flags, field, query);
			};
		};
	} else {
@@ -128,19 +121,19 @@ export fn main() void = {

fn send(
	conn: io::file,
	op: operation,
	op: client::operation,
	flags: flag,
	field: str,
	query: []str,
) void = {
	fmt::fprint(conn, switch (op) {
	case operation::QUERY =>
	case client::operation::QUERY =>
		yield "query";
	case operation::ADD =>
	case client::operation::ADD =>
		yield "add";
	case operation::DEL =>
	case client::operation::DEL =>
		yield "del";
	case operation::QUIT =>
	case client::operation::QUIT =>
		yield "quit";
	})!;
	for (let i = 0z; i < len(query); i += 1) {
-- 
2.37.0
Thanks!

To git@git.sr.ht:~sircmpwn/himitsu
   c7d4942..2de1773  master -> master