neomantra / ymdflag

YMDFlag implements a Golang flag.Value interface for YYYYMMDD-specified dates, facilitating CLI argument handling of dates like -start-date=20210101

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ymdflag

Units tests Coverage Status golangci-lint CodeQL Go ReportCard Go Reference

YMDFlag implements a Golang flag.Value interface for YYYYMMDD-specified dates. This facilitiates command-line argument handling of date parameters such -start-date=20210101.

Documentation

go get github.com/neomantra/ymdflag

https://pkg.go.dev/github.com/neomantra/ymdflag

Examples

There are examples in the examples/ directory. Here's a quick sketch:

package main

import (
	"github.com/neomantra/ymdflag"
	"github.com/spf13/pflag"
)

func main() {
	var ymd ymdflag.YMDFlag
	pflag.VarP(&ymd, "date", "d", "YYYYMMDD date; defaults to today in local time")
	pflag.Parse()
	println("time of date:", ymd.AsTime().String())
}

Credits and License

Copyright (c) 2022-2023 Neomantra BV. Authored by Evan Wies.

Released under the MIT License, see LICENSE.txt.

About

YMDFlag implements a Golang flag.Value interface for YYYYMMDD-specified dates, facilitating CLI argument handling of dates like -start-date=20210101

License:MIT License


Languages

Language:Go 100.0%