Command Line Argument Processing in Go: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 18: Line 18:
</syntaxhighlight>
</syntaxhighlight>


<code>args[0]</code> is the executable.
<code>args[0]</code> is a string that represents the path of the executable, as it was invoked on the command line. Example: <code>./../bin/metadata</code>.

Revision as of 21:54, 16 October 2023

Internal

Overview

Use the flag package:

var port int
flag.IntVar(&port, "port", 8080, "Some documentation for the flag")
flag.Parse()


Positional Arguments

args := os.Args

args[0] is a string that represents the path of the executable, as it was invoked on the command line. Example: ./../bin/metadata.