Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "which" method to Processes and ProcessHelpers #945

Closed
sleberknight opened this issue Apr 17, 2023 · 0 comments · Fixed by #956
Closed

Add "which" method to Processes and ProcessHelpers #945

sleberknight opened this issue Apr 17, 2023 · 0 comments · Fixed by #956
Assignees
Labels
new feature A new feature such as a new class, method, package, group of classes, etc.
Milestone

Comments

@sleberknight
Copy link
Member

Add a generic which method to allow code to find the location of executable programs and scripts that are in the PATH.

The location that seems to make the most sense is the Processes and ProcessHelper classes, since these contain methods related to processes. The which method is related to processes since you can find a program, shell script, etc. and then also use Processes to launch it.

The method signatures can be:

// ProcessHelper.java:
public Optional<String> which(String command) { ... }


// Processes.java:
public static Optional<String> which(String command) { ... }

Usage example:

var vaultPath = Processes.which("ansible-vault");
// do something with it...

In ProcessHelper the which method is an instance method to make it easy to mock if needed in test code.

In Processes the which method should be a static method like everything else in that (pure utility) class. In addition, we might consider returning a "Result" instead of Optional to provide more information (i.e. like an "Either" having a value or an error/exception). However, kiwi doesn't have an Either and I'm not sure we want to add one or depend on another library such as the either library at the present time. Java needs to add one, but that's probably not happening any time soon, or ever.

This originated from discussion #944

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature A new feature such as a new class, method, package, group of classes, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant