A command-line argument is a string passed to a program when it starts. In Go, the runtime exposes raw arguments through os.Args. A command-line interface then interprets those strings as required inputs or as flags that configure behavior. section 4.2 section 4.8
Arguments and flags serve different jobs. Use a positional argument for a mandatory input that defines the tool’s purpose, such as an HTTP server URL. Use flags for optional configuration, such as request count, concurrency, or requests per second. section 4.0 section 4.5
Parsing turns startup strings into values the program can use:
- Read raw strings from os.Args, commonly omitting the program name with os.Args[1:]. section 4.2 section 4.3.2
- Separate a flag such as -n=100 into its name and string value, then convert that value into the target type. section 4.2.1
- Register string and integer destinations with a flag.FlagSet, then call Parse to update those variables automatically. section 4.3.1
- Retrieve positional inputs with FlagSet.Arg only after parsing. section 4.5.1
The standard flag package parses arguments into ordinary type-safe Go variables, generates usage text, and reports parsing failures. A dedicated FlagSet with ContinueOnError lets the program retain control over errors and exit status; avoiding the package-level default FlagSet can also make testing easier. section 4.3 section 4.3.1
Parsing a URL and request settings
A HIT invocation can supply optional settings before its required URL: ./hit -n 1_000_000 -c 20 http://localhost:8082. Here -n and -c configure the run, while the URL identifies the server. Registering the settings in a FlagSet converts their string values into configuration fields; retrieve the URL as the first positional argument after Parse. section 4.0 section 4.3.1 section 4.5.1
Ordering matters for positional arguments: flag parsing stops at the first nonflag argument. Put flags first and positional inputs afterward; otherwise a later token such as -n=1 is treated as positional instead of being parsed as a flag. section 4.5.1
For custom value types, a flag.Value implementation supplies String for a displayed default and Set for parsing and assigning a supplied string. Register it with FlagSet.Var when built-in string, integer, or boolean parsers are not enough. section 4.4.1 section 4.8
$ ./hit -n 1_000_000 -c 20 http://localhost:8082 #1
__ __ __ ______
/\ \_\ \ /\ \ /\__ _\
\ \ __ \ \ \ \ \/_/\ \/
\ \_\ \_\ \ \_\ \ \_\
\/_/\/_/ \/_/ \/_/
Sending 1000000 requests to "http://localhost:8082" (concurrency: 20)
Summary:
Success: 100%
RPS: 97854.73
Requests: 1000000
Errors: 0
Bytes: 12000000
Duration: 10.22s
Fastest: 1ms
Slowest: 5ms
Inspect a complete invocation and its reported request configuration and results; it makes the distinction between option flags and the trailing URL concrete. section 4.0













