Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zakuro9715/nzflag
Normalize args and flags
https://github.com/zakuro9715/nzflag
argv flag golang pkggodev
Last synced: 16 days ago
JSON representation
Normalize args and flags
- Host: GitHub
- URL: https://github.com/zakuro9715/nzflag
- Owner: zakuro9715
- License: apache-2.0
- Created: 2020-11-07T10:36:40.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2021-02-06T14:52:21.000Z (almost 4 years ago)
- Last Synced: 2024-10-17T12:23:57.454Z (2 months ago)
- Topics: argv, flag, golang, pkggodev
- Language: Go
- Homepage:
- Size: 43 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# nzflag
![Test](https://github.com/zakuro9715/nzflag/workflows/Test/badge.svg)
[![codecov](https://codecov.io/gh/zakuro9715/nzflag/branch/main/graph/badge.svg?token=K937ZYFF9Z)](https://codecov.io/gh/zakuro9715/nzflag)
[![GoDoc](https://godoc.org/github.com/zakuro9715/nzflag?status.svg)](http://godoc.org/github.com/zakuro9715/nzflag)
[![PkgGoDev](https://pkg.go.dev/badge/github.com/zakuro9715/nzflag)](https://pkg.go.dev/github.com/zakuro9715/nzflag)
[![Go Report Card](https://goreportcard.com/badge/github.com/zakuro9715/nzflag)](https://goreportcard.com/report/github.com/zakuro9715/nzflag)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)Go library to Normalize argv
From
```
-ab=0 --value1=0 --value2 1
```To
```
-a -b=0 --value=0 --value2=1
```# Install
```
go get github.com/zakuro9715/nzflag
```# Motivation
There are useful and powerful cli libraries for Go.
But I want preprocess argv before run cli library and raw cli args are complex format.
Therefore I created nzflag to preprocess raw argv.# Concept
- Simple
- No validation. No typecheck
- Respect raw argv. So don't swap order as possible as.
- Result of NormalizeToStrings() is valid argv. So it comopatible with other cli Library (like [urfave/cli](https://github.com/urfave/cli]).
- You jest pass result of NormalizeToStrings() as Argv# Feature
- Split short flags (-ab into -a -b)
- Normalize flag with value (--value 0 into value=0)
- Treat as arg after "--" (-f2 -- -f2 # -f2 is arg)
- Merge flags specified multiple times (-a=0 -a=1 into -a=0,1)# Usage
```input
app := New().FlagN("values1", 2).FlagN("values2", 2).FlagN("f", 2)app.NormalizeToStrings([]string{
"-ab", "-cd=c", "--cd=c", "-ef", "x", "x",
"--values1=v", "--values2", "v1", "v2", "arg",
});// Result
[]string{
"-a", "-b", "-c", "-d=c", "--cd=c", "-e", "-f=x,x",
"--values1=v", "--values2=v1,v2", "arg"
}
```See also ![PkgGoDev](https://pkg.go.dev/badge/github.com/zakuro9715/nzflag)](https://pkg.go.dev/github.com/zakuro9715/nzflag) and [test](normalize_test.go)
# CLI Tool
## Install
```
go get github.com/zakuro9715/nzflag/cmd/nzflag
```