liveBook · Manning

Command-line tool

As explained in Go by Example

A command-line tool is a software program operated through textual commands in a shell or terminal.

A command-line tool is a program operated through textual commands in a shell or terminal. It automates tasks with speed, consistency, and configurable behavior. section 4.0

A practical command-line interface separates inputs by purpose:

  • Arguments provide necessary parameters, such as a URL. section 4.0
  • Flags provide optional settings, such as concurrency or verbose output. section 4.0
  • Input parsing can begin with os and progress to flag, including custom flag.Value types and validation. section 4.0

HIT performance tool

A command such as ./hit -n 1_000_000 -c 20 http://localhost:8082 sends one million HTTP requests with concurrency 20, then reports success, requests per second, errors, bytes, duration, and response-time extremes. section 4.0

$ ./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 terminal invocation and its performance summary to connect flags and arguments with observable output. section 4.0

How Go by Example covers it

How deep it goes
Explains arguments, flags, os, flag, custom flag types, and validation, stopping short of detailed parser internals.
Examples
Uses the HIT HTTP performance tool, terminal invocations, performance summaries, and exercises building related tools.
What it assumes
Assumes programming fundamentals and general computer-science concepts while teaching command-line parsing through practical projects.
What you can do after
Build it from scratch with Go's os and flag packages, custom flag types, and input validation.
How it connects
Connects command-line tools with shell commands, arguments, flags, standard-library packages, HTTP clients, and concurrency.

Also explained in

Compare how 3 books explain command-line tool →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Go by Example. The section links point to the parts of the book it draws on.