os.arg
-
The os.Args variable (found in the os package) is a simple slice of
strings. It captures everything typed after the program name in the
terminal.
How it works?
It indexes every space-separated word.
Index 0: Always the path to the program itself.
The Rest: Any arguments passed by the user.
Example: If you run ./myscript save --force --id=10, os.Args looks like this: ["./myscript", "save", "--force", "--id=10"]
The Downside: To use this, you have to manually write logic to figure out what --force means or convert "10" from a string to an integer.
flag package is better than os.args.
Code
|
|