Skip to content

Parse args with standard getopt() instead of custom cli module#83

Closed
slook wants to merge 1 commit intosoulfind-dev:masterfrom
slook:cli-getopt
Closed

Parse args with standard getopt() instead of custom cli module#83
slook wants to merge 1 commit intosoulfind-dev:masterfrom
slook:cli-getopt

Conversation

@slook
Copy link
Copy Markdown
Member

@slook slook commented Mar 28, 2026

This branch is now for experimentation and demonstration purposes only.

  • Changed: Parse args with standard getopt() instead of custom cli module
$ ./bin/soulfind --help
Soulseek server implementation in D
-d --database Database path (default: soulfind.db).
-p     --port Listening port.
      --debug Enable debug logging.
-v  --version Show version.
-h     --help This help information.
$ ./bin/soulfind --protify
Unrecognized option --protify
$ ./bin/soulfind --port
Missing value for argument --port.
$ ./bin/soulfind --port 1234
♥ Soulfind Mar-28-2026 process 2782252 listening on port 1234
^C
A la prochaine...
$ ./bin/soulfind --version
Soulfind Mar-28-2026 (compiled with GNU D 2.100)

This will allow us to do what we want with the new argument options in #81 and #82, we can simply get --log option and process strings in a callback option (see number 8 in the documention for relevant examples) or as an spaced split array with arraySep set to " " (see number 6).

No new options nor functional changes in this PR as to the invoking the program, it works just the same as before.

@mathiascode
Copy link
Copy Markdown
Member

We used getopt in the past, but removed it. See commit 150f4a9 for details.

@slook
Copy link
Copy Markdown
Member Author

slook commented Mar 29, 2026

Thanks. I didn't realize that you had made this decision.

This branch is now for experimentation and demonstration purposes only.

It's interesting to know that getopts() removes each argument that is parses because it's good practice to not leave parsed args hanging around in the args for no reason. For instance the --database filename, I don't think our cli.arg_parse() removes them even after it's not needed anymore.

@slook slook marked this pull request as draft March 29, 2026 10:49
@slook slook closed this Mar 30, 2026
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.

2 participants