flag

package module
v0.0.0-...-abbb622 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2023 License: MIT Imports: 5 Imported by: 0

README

Golang Flag Helper

Simple helper to store your flags in a struct and allow environment overrides

environment and shortname are optional arguments. name, default, and usage are required.

Usage Example

package main

import (
    "fmt"

    "git.127001.link/kormoc/flag"
)

var flags = struct {
    StringExample string `name:"string" shortname:"s" environment:"TEST_STRING" default:"Hello World" usage:"String Test"`
    IntExample    int    `name:"int"    shortname:"i" environment:"TEST_INT"    default:"8"           usage:"Int Test"`
    BoolExample   bool   `name:"bool"   shortname:"b" environment:"TEST_BOOL"   default:"true"        usage:"Bool Test"`
}{}

func main() {
    if err := flag.Parse(&flags); err != nil {
        log.Fatal(err)
        os.Exit(1)
    }

    fmt.Printf("%+v\n", flags)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Args

func Args() []string

func Parse

func Parse(flag interface{}) error

Types

This section is empty.

Jump to

Keyboard shortcuts

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