Package osargs provides functions to parse command line arguments

osargs

GoDoc Go Report Card Stability: Experimental

About

Package osargs provides functions to parse command line arguments. It is published on https://github.com/vbsw/osargs and https://gitlab.com/vbsw/osargs.

Copyright

Copyright 2021, Vitali Baumtrok ([email protected]).

osargs is distributed under the Boost Software License, version 1.0. (See accompanying file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt)

osargs is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Boost Software License for more details.

Usage

Example A

package main

import (
	"fmt"
	"github.com/vbsw/osargs"
)

func main() {
	args := osargs.New()

	if args.Parse("--help", "-h").Available() {
		fmt.Println("valid parameters are -h or -v.")

	} else if args.Parse("--version", "-v").Available() {
		fmt.Println("version 1.0.0")

	} else {
		unparsedArgs := args.UnparsedArgs()

		if len(unparsedArgs) == 1 {
			fmt.Println("error: unknown parameter", unparsedArgs[0])

		} else if len(unparsedArgs) > 1 {
			fmt.Println("error: too many arguments")
		}
	}
}

Example B

package main

import (
	"fmt"
	"github.com/vbsw/osargs"
)

func main() {
	start := "0"
	end := "0"
	args := osargs.New()
	delimiter := osargs.NewDelimiter(false, false, "=")

	startArg := args.ParsePairs(delimiter, "start")
	endArg := args.ParsePairs(delimiter, "end")

	if startArg.Available() {
		start = startArg.Values[0]
		end = start
	}
	if endArg.Available() {
		end = endArg.Values[0]
	}
	fmt.Println("processing from", start, "to", end)
}

Command line:

$ ./test start=1 end=10
$ processing from 1 to 10

References

Owner
Similar Resources

git-xargs is a command-line tool (CLI) for making updates across multiple Github repositories with a single command.

git-xargs is a command-line tool (CLI) for making updates across multiple Github repositories with a single command.

Table of contents Introduction Reference Contributing Introduction Overview git-xargs is a command-line tool (CLI) for making updates across multiple

Dec 31, 2022

git-xargs is a command-line tool (CLI) for making updates across multiple GitHub repositories with a single command

git-xargs is a command-line tool (CLI) for making updates across multiple GitHub repositories with a single command

git-xargs is a command-line tool (CLI) for making updates across multiple GitHub repositories with a single command. You give git-xargs:

Feb 5, 2022

A command line tool for simplified docker volume command built with go

dockervol A command line tool for simplified docker volume command built with go. Features: Remove anonymous volume (beta) Remove volume by matching n

Dec 18, 2021

Watcher - A simple command line app to watch files in a directory for changes and run a command when files change!

Watcher - Develop your programs easily Watcher watches all the files present in the directory it is run from of the directory that is specified while

Mar 27, 2022

UltiTuner: a small helper tool to configure functions for Ultimaker S-Line printers

UltiTuner UltiTuner is a small helper tool to configure functions for Ultimaker

Apr 25, 2022

CLI - A package for building command line app with go

CLI - A package for building command line app with go

Command line interface Screenshot Key features Lightweight and easy to use. Defines flag by tag, e.g. flag name(short or/and long), description, defau

Dec 23, 2022

A simple, fast, and fun package for building command line apps in Go

cli cli is a simple, fast, and fun package for building command line apps in Go. The goal is to enable developers to write fast and distributable comm

Dec 31, 2022

✍ A package and command line tool to generate Lorem Ipsum

✍ A package and command line tool to generate Lorem Ipsum

Lorelai A package and command line tool to generate Lorem ipsum. Install go get github.com/UltiRequiem/lorelai/pkg Examples Generating Text func print

Jul 27, 2022

Package varflag implements command-line flag parsing into vars.Variables for easy type handling with additional flag types.

varflag Package flag implements command-line flag parsing into vars.Variables for easy type handling with additional flag types. varflag Flags String

Aug 2, 2022
A tool to enumerate all the command-line arguments used to start a Linux process written in Go.
A tool to enumerate all the command-line arguments used to start a Linux process written in Go.

ranwith A tool to enumerate all the command-line arguments used to start a Linux process written in Go. ranwith uses the Linux /proc directory to obta

Jun 30, 2022
Go cmd utility that prints its command line arguments using strings.Join

Results This is an exercise of the book The Go Programming Language, by Alan A. A. Donovan and Brian Kernighan. Comparison between different versions

Dec 18, 2021
An open-source GitLab command line tool bringing GitLab's cool features to your command line
An open-source GitLab command line tool bringing GitLab's cool features to your command line

GLab is an open source GitLab CLI tool bringing GitLab to your terminal next to where you are already working with git and your code without switching

Dec 30, 2022
A command line tool that builds and (re)starts your web application everytime you save a Go or template fileA command line tool that builds and (re)starts your web application everytime you save a Go or template file

# Fresh Fresh is a command line tool that builds and (re)starts your web application everytime you save a Go or template file. If the web framework yo

Nov 22, 2021
A command line tool to prompt for a value to be included in another command line.

readval is a command line tool which is designed for one specific purpose—to prompt for a value to be included in another command line. readval prints

Dec 22, 2021
Go package to make lightweight ASCII line graph ╭┈╯ in command line apps with no other dependencies.
Go package to make lightweight ASCII line graph ╭┈╯ in command line apps with no other dependencies.

asciigraph Go package to make lightweight ASCII line graphs ╭┈╯. Installation go get github.com/guptarohit/asciigraph Usage Basic graph package main

Jan 8, 2023
A simple go program which checks if your websites are running and runs forever (stop it with ctrl+c). It takes two optional arguments, comma separated string with urls and an interval.

uptime A simple go program which checks if your websites are running and runs forever (stop it with ctrl+c). It takes two optional arguments: -interva

Dec 15, 2022
Package command provide simple API to create modern command-line interface

Package command Package command provide simple API to create modern command-line interface, mainly for lightweight usage, inspired by cobra Usage pack

Jan 16, 2022
A CLI command to parse Terraform execution result and notify it to Backlog
A CLI command to parse Terraform execution result and notify it to Backlog

tf2b Fork of mercari/tfnotify tf2b parses Terraform commands' execution result and applies it to an arbitrary template and then notifies it to Backlog

Oct 15, 2021
This package can parse date match expression, which used by ElasticSearch

datemath-parser this package is pure go package, this package can parse date match expression, which used by ElasticSearch. Date Math Definition you c

Jan 8, 2022