Search⌘ K
AI Features

Exercise: Adding and Validating Flags

Learn to enhance your Go-based CLI tool by adding a string flag for filtering port scan results with options 'all', 'open', or 'closed'. Understand how to implement input validation using Cobra's PreRunE function and update output behaviors accordingly. This exercise also encourages writing tests to ensure correctness.

We'll cover the following...

Challenge

In this exercise, your challenge is to add a new flag and some validation to the pScan tool.

Problem Statement

Add a new flag to pScan scan subcommand allowing the user to specify a filter to show only open or closed ports.

Coding Challenge

Add a new flag to the ...