Skip to content
/ flag Public

Adds flag implementations like multi values argument or limited to predefined varians.

Notifications You must be signed in to change notification settings

m4gshm/flag

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flag

Extends the core flag package by adding implementations, such as an argument with multiple values or an argument limited to predefined options.

Example

source example.go:

package main

import (
    "flag"
    "fmt"

    "github.com/m4gshm/flag/flagenum"
)

func main() {
    var (
        api = flagenum.MultipleStrings(
            "api",
            []string{"rest", "grpc"},         /*default*/
            []string{"rest", "grpc", "soap"}, /*allowed*/
            "enabled api engine",
        )
        logLevel = flagenum.SingleString(
            "log-level",
            "info", /*default*/
            []string{"debug", "info", "warn", "error"}, /*allowed*/
            "logger level",
        )
    )
    flag.Parse()

    fmt.Printf("enabled apis: %v\n", *api)
    fmt.Printf("log level:    %s\n", *logLevel)
}

Command go run . will print:

enabled apis: [rest grpc]
log level:    info

To change defaults need set arguments like go run . --api soap --api rest --log-level debug

enabled apis: [soap rest]
log level:    debug

Call go run . --help to get usage info:

Usage of example:
  -api any of rest,grpc,soap
        enabled api engine (allowed any of rest,grpc,soap) (default rest,grpc)
  -log-level one of debug,info,warn,error
        logger level (allowed one of debug,info,warn,error) (default info)

About

Adds flag implementations like multi values argument or limited to predefined varians.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published