4 ms·
I haven't used PHP for CLI scripting, however I've used Python and Golang. I can say that Golang argument library (flag) feels more straightforward to me than P
by terminalcommand 9y ago
I haven't used PHP for CLI scripting, however I've used Python and Golang. I can say that Golang argument library (flag) feels more straightforward to me than Python's argparse.
import "flag"
var ip = flag.Int("flagname", 1234, "help message for flagname")
...
// flag.Parse() once in the main function
vs
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("square", help="display a square of a given number",
type=int)
...
args = parser.parse_args()
In the Go example you get a pointer just like in C, in the python example you get a special object and can access its fields. Both are simple, but Golang is IMHO closer to C in this matter.
- camus2 9y agoPHP and C have getopt in their standard library which work mostly the same way. flag package bothers me because it breaks getopt conventions for no good reason.