GithubHelp home page GithubHelp logo

fuckflag's Introduction

fuckflag

A golang flag lib which support undefined flags.

Story

Here's the thing... When I tried to create a command line tool with golang, I found the flag.Parse() will throw an error like this:

flag provided but not defined: -xxx

So I modified the src code, and that's how fuckflag was born.

Install

go get -u github.com/sshelll/fuckflag

Demo

package main

var (
	version = fuckflag.Bool("v", false, "print version")
	echo    = fuckflag.String("echo", "", "echo string")
)

func main() {
	fuckflag.Parse()
	if *version {
		println("v0.0.1")
	}
	if *echo != "" {
		println("echo: " + *echo)
	}
	// call this func to get undefined flags
	exts := fuckflag.Extends()
	fmt.Printf("fuckflag.Extends() size=%d, value=%v\n", len(exts), exts)
	// call this the check if a flag was passed
	vset, eset := fuckflag.IsSet("v"), fuckflag.IsSet("echo")
	fmt.Printf("version.set=%v, echo.set=%v\n", vset, eset)
}

Exec Result:

>> go build -o test main.go

>> ./test -v -echo=hello -undef --x -p=1

>> output:
v0.0.1
echo: hello
fuckflag.Extends() size=3, value=[-undef --x -p=1]
version.set=true, echo.set=true

fuckflag's People

Contributors

sshelll avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.