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: 0

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