Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
For scripting what are the pros and cons of command line arguments versus capturing input at the start?
Let's say I have a script that needs the user to set X number of variables at the start. One can either
- Pass the arguments in on the command line.
- Start the program and then have the user input the variables with Python's
input()function or PHP's
fopen("php://stdin", "r")for example.
What would the pros and cons be and when would I decide to use one method versus the other?
Pros of CLI arguments/flags include: Easier to leverage the tool in another script or via other automation so that …
I'd like to move the frame out a little and use that as a discussion for how to make these decisions. Input models …
I'm coming down strongly in favor of command-line arguments or options over interactive I/O for a number of reasons: …
I would like to add further options to the set of possibilities, namely environment variables and GUI input. Moreover, …
@laserkittens and @dmckee has already provided good answers, and I will not copy what's there. Personally, I treat …
I largely agree with existing answers, but wanted to add this: In many cases, there is no clear answer one way or the …