default

command
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 8, 2022 License: MIT Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Default Argument Value

To demonstrate usage of default values of arguments.

Setup

parser := argparse.NewParser("default", "Program to test default values")

Required is false

Create an argument where the required option is set to false:

s := parser.String("s", "string", &argparse.Options{Required: false, Help: "String to print", Default: "Hello"})

On execution of program, which prints the argument as

fmt.Println(*s)
$ go run default.go
Hello

Also, the default value is printed in the help.

Required is true

s := parser.String("s", "string", &argparse.Options{Required: true, Help: "String to print", Default: "Hello"})

On execution,

$ go run default.go
[-s|--string] is required
usage: default [-h|--help] -s|--string "<value>"

               Program to test default values

Arguments:

  -h  --help    Print help information
  -s  --string  String to print

exit status 1

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL