/flagvar

Collection of useful flag.Value implementations.

Primary LanguageGo

flagvar

A tiny library with collection of flag.Value implementations

Overview

This is a collection of different useful flag.Value implementations. Works good with flagutil library.

Under development right now.

Usage

Here is a simple program that reads a date from the flag and prints it as a unix timestamp:

package main

import (
	"flag"
	"time"

	"github.com/gobwas/flagvar"
)

func main() {
	flags := flag.NewFlagSet("time", flag.ExitOnError)	
	
	var t time.Time
	flags.Var(&flagvar.Time(&t, "02.01.2006"),
		"date", 
		"time to print as a unix timestamp in form `dd.mm.yyyy`",
	)
	
	flags.Parse()

	fmt.Fprintln(os.Stdout, t.Unix())	
}