~sircmpwn/hare-dev

hautils: yes: new command v3 REJECTED

jgart: 1
 yes: new command

 2 files changed, 25 insertions(+), 1 deletions(-)
Hi Sebastian,
Next
The performance of yes(1) is not of any conseqeunce. Simplicity is the
word.


It seems that hautils might lean more in the spirit/aesthetics of sbase but I may be wrong:

https://github.com/michaelforney/sbase

Thanks for the all the code reviews. Much appreciated!

--
jgart
Skipping this on the basis that it's not POSIX.
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/hare-dev/patches/39206/mbox | git am -3
Learn more about email & git

[PATCH hautils v3] yes: new command Export this patch

hi,

v3 simplies some logic in the if statement

---
 Makefile |  4 +++-
 yes.ha   | 22 ++++++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)
 create mode 100644 yes.ha

diff --git a/Makefile b/Makefile
index c568580..298db4b 100644
--- a/Makefile
+++ b/Makefile
@@ -18,7 +18,8 @@ utils=\
	true \
	uname \
	uniq \
	wc
	wc \
	yes

all: $(utils)

@@ -46,3 +47,4 @@ true: true.ha
uname: uname.ha main/main.ha
uniq: uniq.ha main/main.ha
wc: wc.ha main/main.ha
yes: yes.ha main/main.ha
diff --git a/yes.ha b/yes.ha
new file mode 100644
index 0000000..957bbc0
--- /dev/null
+++ b/yes.ha
@@ -0,0 +1,22 @@
use fmt;
use getopt;
use os;
use main;

export fn utilmain() (main::error | void) = {
	const help: []getopt::help = [
		"output string repeatedly",
		"<string>",
	];
	const cmd = getopt::parse(os::args, help...);
	defer getopt::finish(&cmd);
	if (len(cmd.args) > 1) {
		getopt::printhelp(os::stderr, os::args[0], help);
		os::exit(1);
	};
	const s = if (len(cmd.args) == 1) cmd.args[0] else "y";
	for (true) {
		fmt::printfln(s)!;
	};
	return void;
};
-- 
2.39.1

fmt::printfln should not be used, because s is not a format string:

master$ ./yes '{}'
Abort: /usr/src/hare/stdlib/fmt/fmt.ha:220:31: Not enough parameters given
Aborted (core dumped)

You should use fmt::println instead.