didumean

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2023 License: MIT Imports: 7 Imported by: 5

README

didumean

ci Documentation Go Report Card

go flag package wrapper, for did you mean function

Usage

see details in godoc

package main

import (
	"fmt"
	"flag"

	"github.com/mashiike/didumean"
)

func main() {  
    var (
        name string
    )
    flag.StringVar(&name, "name", "noname", "name parameter")
    didumean.Parse() // replace your flag.Parse()
    fmt.Println(name)
}

example execution:

$ ./example -none hoge
flag provided but not defined: -none, did you mean -name
Usage of ./example:
  -name string
        name parameter (default "noname")

LICENSE

MIT

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse()

Parse as flag.Parse with did you mean.

Example
package main

import (
	"bytes"
	"flag"
	"fmt"
	"os"

	"github.com/mashiike/didumean"
)

func main() {
	var buf bytes.Buffer
	flag.CommandLine = flag.NewFlagSet("example", flag.ContinueOnError)
	flag.CommandLine.SetOutput(&buf)
	os.Args = []string{"example", "-staing", "hoge"}

	var (
		val int
		str string
		on  bool
	)
	flag.IntVar(&val, "value", 0, "value")
	flag.StringVar(&str, "string", "", "string")
	flag.BoolVar(&on, "on", false, "on")
	didumean.Parse()

	fmt.Println(buf.String())
}
Output:

flag provided but not defined: -staing, did you mean -string
Usage of example:
  -on
    	on
  -string string
    	string
  -value int
    	value

Types

type FlagSet

type FlagSet struct {
	*flag.FlagSet
	// contains filtered or unexported fields
}

FlagSet is *flag.FlagSet wrapper with did you mean function.

func NewFlagSet

func NewFlagSet(name string, handling flag.ErrorHandling) *FlagSet

NewFlagSet create wraped FlagSet

func (*FlagSet) Parse

func (f *FlagSet) Parse(arguments []string) error

Parse as flag.FlagSet.Parse with did you mean.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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