flags

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2019 License: Apache-2.0 Imports: 7 Imported by: 0

README

flags

Package flags implements command-line flag parsing for types that are not part of the standard library flag package, but I consider to be useful.

docs

The available flags are:

HexColor flags

You can use them like this:

package main

import (
	"flag"
	"fmt"
	"image/color"

	"github.com/campoy/tools/v2/flags"
)

func main() {
	a := flags.HexColor("a", color.White, "color a")
	var b color.Color
	flags.HexColorVar(&b, "b", color.White, "color b")
	flag.Parse()

	fmt.Printf("a is %v; b is %v", a, b)
}

TextTemplate flags

You can use them like this:

package main

import (
	"flag"
	"fmt"
	"log"
	"os"
	"text/template"

	"github.com/campoy/tools/v2/flags"
)

func main() {
	a := flags.TextTemplate("a", "Hello, {{.Name}}", "template a")
	var b template.Template
	flags.TextTemplateVar(&b, "b", "Hola, {{.Name}}", "template b")
	flag.Parse()

	data := struct{ Name string }{"Francesc"}
	fmt.Printf("template a: ")
	if err := a.Execute(os.Stdout, data); err != nil {
		log.Fatal(err)
	}
	fmt.Print("\ntemplate b: ")
	if err := b.Execute(os.Stdout, data); err != nil {
		log.Fatal(err)
	}
	fmt.Println()
}
Disclaimer

This is not an official Google product (experimental or otherwise), it is just code that happens to be owned by Google.

Documentation

Overview

Package flags implements command-line flag parsing for types that are not part of the standard library flag package, but I consider to be useful.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HexColor

func HexColor(name string, value color.Color, usage string) color.Color

HexColor defines a hex color flag with specified name, default value, and usage string. The return value is the address of an RGBA color variable that stores the value of the flag.

func HexColorVar

func HexColorVar(c *color.Color, name string, value color.Color, usage string)

HexColorVar defines a hex color flag with specified name, default value, and usage string. The argument c points to an RGBA color variable in which to store the value of the flag.

func TextTemplate

func TextTemplate(name string, value string, usage string) *template.Template

TextTemplate defines a text template flag with specified name, default value, and usage string. The return value is the address of a text template variable that stores the value of the flag. If the given template fails to compile an error will be logged and the program will exit with exit code 2. (os.Exit(2))

func TextTemplateVar

func TextTemplateVar(t *template.Template, name string, value string, usage string)

TextTemplateVar defines a text template flag with specified name, default value, and usage string. The argument t points to a text template variable in which to store the value of the flag. If the given template fails to compile an error will be logged and the program will exit with exit code 2. (os.Exit(2))

Types

This section is empty.

Directories

Path Synopsis
samples

Jump to

Keyboard shortcuts

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