A rich tool for parsing flags and values in pure Golang

Arg Parser

====================================

A rich tool for parsing flags and values in pure Golang. No additional library is required and you can use everywhere.

Features

  • Supporting different formats:
	int (int64, int32, int16, int8)
	uint (uint64, uint32, uint16, uint8)
	string // (you can easily convert any type to string)
	bool // yes, on, true, 1 = true; no, off, false, 0 = false
  • Easily convert each type to another types. with only one functions.

  • Low time order! It's as fast as spliting two strings and then joining them together XD

  • Simple algorithms. You can easily read the algorithms used in this library, and you are allowed to copy and use them in your own projects (even if they are in Golang or not)!

  • No additional libs. You don't have to waste your time and storage for downloading another libraries and dependencies. Only this lib, will meet your needs.

  • Supports multi flags with the same name (Of course they have different indexes).

  • Rigorously tested. We are testing the lib in any possible ways. If you find out a bug, please create an issue on our issue tracker. We will check it and solve the problem


Examples:

parsing a command is a simple work!

const text = "/test --flag1 true --flag2 on" +
	" --flag3 false" +
	" --flag4 \"Hello, how are you?\"" +
	" --flag5 off\n\n\n\n\n\n" +
	" --flag6 123456789"

	//-----------------------------------------------------

	// parse it and get an *EventArgs value.
	args, err := argparser.ParseArg(boolTest)
	if err != nil {
		// if the format of the text is not correct,
		// you will get an error.
		// if you find out any bug here, please report us.
		// if the text doesn't contain ant command, you will
		// get error (it should start with command.)
		log.Fatal(err)
	}

	// check if it contains any flag with name `flag1` or not?
	if args.HasFlag("flag1", "anotherFlag") {
		// doesn't matter this
		log.Println("it has flag1 or anotherFlag")
	}

	// get a flag's value as bool.
	// if the flags are not present in EventArgs at all,
	// this method will return false.
	// if it's on, yes, true, 1 (one integer), it returns true
	// if it's off, no, false, 0, it returns false
	// if it's string, it will return true
	// if it doesn't have any value (empty string), it returns true
	// 
	b1 := args.GetAsBool("flag1")
	if b1 {
		log.Println("it's true!")
	} else {
		log.Println("it's false!")
	}

	s1 := args.GetAsString("flag4")
	log.Println(s1) // Hello, how are you?

	// lets try more than one flag this time.
	// this method will search for the flags you passed to it.
	// if the first flag doesn't exist, it will look
	// for another one.
	// if there are no such flags at all, it will return you
	// `0, false`
	// if the first flag exists but it can't be
	// converted to integer, it will give you `0, false`s
	i1, ok := args.GetAsInteger("flag6", "flag10")
	if !ok {
		log.Println("couldn't parse flag value to integer")
	} else {
		log.Println("oh yeah, the integer value is ", i1)
	}

need more examples? then take a look at example directory!


How to get started?

  • Download the library with the standard go get command:

go get github.com/ALiwoto/argparser

Support and Contributions

If you think you have found a bug or have a feature request, feel free to use our issue tracker. Before opening a new issue, please search to see if your problem has already been reported or not. Try to be as detailed as possible in your issue reports.

If you need help using argparser or have other questions we suggest you to join our telegram community. Please do not use the GitHub issue tracker for personal support requests.

Docs

Docs can be found here.

Be sure to read them carefuly!

License

The argparser project is under the MIT License. See the LICENSE file for more details.

Owner
Similar Resources

A command line tool for filling missing metric values on Mackerel.

mackerel-null-bridge A command line tool for filling missing metric values on Mackerel. Description When sending error metrics, etc., you may be force

Jan 11, 2022

Rdelf2json - CLI application for parsing ELF and converting to json

rdelf2json CLI application for parsing ELF and converting to json Install go ins

Jan 22, 2022

🚀 Platform providing a powerful and fast public script parsing API dedicated to the Skript community.

SkriptMC-Parser is currently a prototype in the early stages of development of a system that allows the Skript community to test their scripts via a public API for potential errors or warnings. This is a quick and easy way to check your scripts without having to set up a Spigot server on your environment.

Mar 3, 2022

Go generator to copy values from type to type and fields from struct to struct. Copier without reflection.

Copygen is a command-line code generator that generates type-to-type and field-to-field struct code without adding any reflection or dependenc

Dec 29, 2022

A prediction program which analyzes given numbers and calculates new values

Guess-It-2 About This is a prediction program which analyzes given numbers and calculates new values. Usage To test the program, download this zip fil

Nov 30, 2021

A command line http test tool. Maintain the case via git and pure text

A command line http test tool. Maintain the case via git and pure text

httptest A command line http test tool Maintain the api test cases via git and pure text We want to test the APIs via http requests and assert the res

Dec 16, 2022

Flag is a simple but powerful command line option parsing library for Go support infinite level subcommand

Flag Flag is a simple but powerful commandline flag parsing library for Go. Documentation Documentation can be found at Godoc Supported features bool

Sep 26, 2022

Struct-based argument parsing in Go

Struct-based argument parsing in Go

go-arg Struct-based argument parsing for Go Declare command line arguments for your program by defining a struct. var args struct { Foo string Bar b

Jan 8, 2023

Go library for Parsing Ansible inventory files

aini Go library for Parsing Ansible inventory files. We are trying to follow the logic of Ansible parser as close as possible. Documentation on ansibl

Jan 5, 2023
Generate flags by parsing structures

Flags based on structures. The sflags package uses structs, reflection and struct field tags to allow you specify command line options. It supports di

Nov 24, 2022
Prompts users to enter values for required flags in Cobra CLI applications

Cobra Flag Prompt Cobra Flag Prompt prompts users to enter values for required flags. It is an extension of Cobra, and requires that you use Cobra to

Nov 13, 2021
archy is an static binary to determine current kernel and machine architecture, with backwards compatible flags to uname, and offers alternative output format of Go runtime (i.e. GOOS, GOARCH).

archy archy is an simple binary to determine current kernel and machine architecture, which wraps uname and alternatively can read from Go runtime std

Mar 18, 2022
Automatically sets up command line flags based on struct fields and tags.
Automatically sets up command line flags based on struct fields and tags.

Commandeer Commandeer sets up command line flags based on struct fields and tags. Do you... like to develop Go apps as libraries with tiny main packag

Dec 1, 2022
Terminal UI library with rich, interactive widgets — written in Golang
Terminal UI library with rich, interactive widgets — written in Golang

Rich Interactive Widgets for Terminal UIs This Go package provides commonly needed components for terminal based user interfaces. Among these componen

Jan 7, 2023
Drop-in replacement for Go's flag package, implementing POSIX/GNU-style --flags.

Description pflag is a drop-in replacement for Go's flag package, implementing POSIX/GNU-style --flags. pflag is compatible with the GNU extensions to

Dec 30, 2022
A go1.18 wrapper to provide simple generics based API for defining command line flags.

gflag A go1.18 wrapper to provide simple generics based API for defining command line flags. Example package main import ( "flag" "fmt" "time" "

Dec 20, 2021
Go-flags wireframing demo

go-flags-demo redo - global option redo Redo global option via automatic code-gen TOC go-flags-demo - global option redo Synopsis Usage Development Hi

Jan 22, 2022
Secure, private and feature-rich CLI password manager
Secure, private and feature-rich CLI password manager

Kure Kure is a free and open-source password manager for the command-line. This project aims to offer the most secure and private way of operating wit

Nov 17, 2022
This CLI tool sends HTTP GET requests and print MD5 hash values of the response's body

HTTP Body Hash Generator This CLI (Command Line Interface) tool sends HTTP GET requests and print MD5 hash values of the response's body. Usage You ne

Feb 10, 2022