Warning: This may be a stupid/atypical question but I just don't know what to do. Any suggestion is welcome when it comes to change the existing behavior as long as the features are the same.
The behavior of the cli tool
I'm making a tmux session manager(yes another one). The goal was to have a way to pre-configure tmux sessions with some nice lang like rhai, and then to be able to switch between them in a fuzzy finder. But I also wanted to have the ability to create a configuration for the session based on repositories found on the system. The session would have the name of the repo and the root would be the path to the repositroy. Then a config can be created for it(I was thinking of optionally extending that to custom sessions).
The problem
I wanted the tool to be modular and configurable to users content hence I decided it would be a good idea if I just printed the found repo names(just the name of the top level directory of the path for readability reasons, there is an algo that disambiguates the names) to stdout and then this would be piped to a tool like fzf, then the picked session would be passed as an argument to my tool which would spawn an editor for that session. This would look something like:
session-manager new-session $(session-manager find-repos | fzf)
This design makes it so that the new-session subcommand doesn't have access to paths to those repostiories, which is needed. Because of this we have to store the previously found names of repos and their paths on the filesystem. This creates a problem where the user can run new-session after they created a new repo but if they haven't executed find-repos before that then we don't know where is the path of that repo, or if it's a repo at all. I don't know how to design the interface for it to be intuitive, modular and a the same time more resistant against putting the program in a bad state.
The potential solutions
- Search for the repo when the user executes
new-sessionwith a session name that is not found. This has the downside of being slow, and is generally a weird solution because what to do when there are multiple repositories with the same top level name - Change the names of subcommands to make it clear that the search must be done just before a session is created
- Change behaviour and somehow forcing the search to be done when creating a session. If someone wants to suggest this, please describe the behaviuor in detail.
- Completly redesign the flow. I'm also open to such a suggestion.
- Encapsulate searching with a higher level command that's defined in the config. This slightly reduces the freedom of the user to do whatever they want and I don't know if there could be security concerns. but it would make the interface intuitive
I'm mainly asking about how would you desigin such a cli application, how would the behaviour look how would the subcommands be named etc. I really tried to describe the behavior the best I could, but I realize that my description could have not been detailed enough in case of any questions, I'll be glad to clarify.
find-reposcommand just before the selecting. Basically suggest one of possible solution that I mentioned or something new. As for you suggestion I would rather not depend directly on the users shell environment. The example with the pipe is a possible solution a user choose but they're free to do something else that fits their needs.