I am the user in question. I also downvoted the accepted answer.
The question is much worse than "not perfect". I explained my reasoning in a comment on the question:
Please read How to Ask and https://ericlippert.com/2014/03/05/how-to-debug-small-programs. Note well that this is not a discussion forum; "Any help would be appreciated!" is not how the site works. We expect a specific, clear question up front, which results from your own best attempt to locate and describe a specific problem. This starts with you carefully checking what the code does, step by step, and figuring out where that diverges from your expectation. After that, focus on that part of the code with a minimal reproducible example.
To be clear: these factors make the question worthy of closure, and not on topic for the site. Aside from the fact that there is not actually a question (the title ends with a question mark, but it is really just describing an undesired behaviour), it is essentially a request to debug several dozen lines of code.
"Sufficient background" does not save a question. It's often not helpful - it's only really necessary for OP to explain why something is being attempted, if it's an inherently strange thing to attempt.
The example is not a minimal reproducible example because it is not minimal. It is the entire command parser. Before posting, it is OP's responsibility to check what the code does, step by step; to have a specific mental model for what should happen at each step (in order to solve the problem); to identify where the code starts doing something different; and to create a code example which isolates that undesired behaviour.
The question being asked is about what ends up in the args
list that is passed to some command. So right off the top we already know that everything in the code that has to do with looking up the command and invoking it, is completely unrelated - the problem has already occurred. So the entire if os.path.exists(commands_dir) and os.path.isdir(commands_dir):
block is irrelevant, right off the top. All the error handling and fancy display of error messages is also irrelevant, because we're considering a case where the program is expected not to report an error.
Keep in mind that the purpose of Stack Overflow is to build a searchable Q&A library. Who would search for this? If we actually isolate the problem, then it would be someone who has the same problem. For such a person to find the question, the question has to reflect that problem.
Because it takes a lot of words to explain the specific way that the code is going wrong, a succinct question would instead focus on the task: something like "How can I parse a string into separate words, but treat quoted strings as a single word?". I tried to put that into simple language because I expect that someone asking this question wouldn't know the relevant terminology (words like tokenization).
But at any rate, once we have identified a question like that, we have something that can be researched. I did not get that far because I was looking at so much code; but if the question had been properly asked I might have then searched for a duplicate to use for closure (rather than casting a "needs MRE" close vote).