Skip to content

Init more carefully and accept enter to terminate user name input#18

Merged
arvidj merged 7 commits intoahrefs:masterfrom
arvidj:aj/init-carefully
Feb 24, 2026
Merged

Init more carefully and accept enter to terminate user name input#18
arvidj merged 7 commits intoahrefs:masterfrom
arvidj:aj/init-carefully

Conversation

@arvidj
Copy link
Contributor

@arvidj arvidj commented Feb 18, 2026

Fixes #16 and #17.

  • passage init bails out if ~/.config/passage exists, unless --force is passed.
  • user name input is terminated by newline. I think this is more user friendly, but a consequence is that new lines are no longer accepted in identity names. A change in semantics, but it seems better to me. Actually, I think we should forbid: empty identity names and identity names that are not composed for a-zA-Z_-.@0-9 or some similarly restricted set.

@arvidj arvidj marked this pull request as ready for review February 18, 2026 10:07
@arvidj arvidj changed the title init more carefully Init more carefully and accept enter to terminate user name input Feb 18, 2026
Copy link
Contributor

@thatportugueseguy thatportugueseguy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, just some minor nitpicks wrt the terms used

lib/commands.ml Outdated
input;
Buffer.contents buf
match In_channel.input_line stdin with
| None -> die "E: EOF while reading user name."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe some more user-friendly message? 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, sure! I'm not sure what is more friendly though. You can make this error appear by pressing Ctrl-D in the terminal with no input. Or by redirecting /dev/null to the process:

$ dune exec bin/main.exe -- init --force

Welcome to passage initial setup.

...

What should be the name used for your recipient identity?
E: Passage init failed: Failure("E: username input was terminated by EOF before a newline was encountered. Ensure the username is newline-terminated and try again")

perhaps it should just say:

E: Passage init failed: Empty user name.

?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, that makes more sense and is understandable by non-techies :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, see latest version!

Note that I also moved the try/catch around a bit (here: 56797b9). Before, if we couldn't read the username for some reason, we would remove the config dir (granted that --force had been passed). I changed the code s.t. the config dir is only removed if we actually read the user name successfully and so had started writing to the config dir. This seems a bit more gentle, and less risk for data loss. Makes sense to you?

lib/commands.ml Outdated
Comment on lines 40 to 41
let line = String.trim line in
let buf = Buffer.create String.(length line) in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let line = String.trim line in
let buf = Buffer.create String.(length line) in
let buf = Buffer.create String.(length (trim line)) in

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC The var line is read below by String.iter, so if I trim as you suggested initial whitespace would be changed to _ instead of trimmed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, you're right, i missed that usage. 👍

@thatportugueseguy
Copy link
Contributor

I think we should forbid: empty identity names and identity names that are not composed for a-zA-Z_-.@0-9

I agree on this one. Probably better on another PR, given the scope?

@arvidj
Copy link
Contributor Author

arvidj commented Feb 24, 2026

Merged after discussion on slack.

@arvidj arvidj merged commit ec81480 into ahrefs:master Feb 24, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Recognize enter in passage init

2 participants