Skip to content

Commit

Permalink
Change License and update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
goloop committed Jun 6, 2023
1 parent f77a9c5 commit 8181b56
Show file tree
Hide file tree
Showing 15 changed files with 107 additions and 674 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@
# Dependency directories
# vendor/
.vscode/
cmd/
cmd/

coverage.out
463 changes: 0 additions & 463 deletions .godocdown.md

This file was deleted.

41 changes: 19 additions & 22 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
Copyright (c) 2022, GoLoop.
All rights reserved.
MIT License

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the GoLoop nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
Copyright (c) 2020 GoLoop

THIS SOFTWARE IS PROVIDED BY COPYRIGHT HOLDER AND CONTRIBUTORS ''AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER AND CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
59 changes: 0 additions & 59 deletions Makefile

This file was deleted.

14 changes: 5 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
[//]: # (!!!Don't modify the README.md, use `make readme` to generate it!!!)


[![Go Report Card](https://goreportcard.com/badge/github.com/goloop/opt)](https://goreportcard.com/report/github.com/goloop/opt) [![License](https://img.shields.io/badge/license-BSD-blue)](https://github.com/goloop/opt/blob/master/LICENSE) [![License](https://img.shields.io/badge/godoc-YES-green)](https://godoc.org/github.com/goloop/opt)


*Version: v1.0.3*
[![Go Report Card](https://goreportcard.com/badge/github.com/goloop/opt)](https://goreportcard.com/report/github.com/goloop/opt) [![License](https://img.shields.io/badge/license-MIT-brightgreen)](https://github.com/goloop/opt/blob/master/LICENSE) [![License](https://img.shields.io/badge/godoc-YES-green)](https://godoc.org/github.com/goloop/opt)

# opt

Expand All @@ -14,7 +8,9 @@ Package opt implements methods for manage arguments of the command-line.

To install this package we can use `go get`:

$ go get -u github.com/goloop/opt
```
$ go get -u github.com/goloop/opt
```

## Usage

Expand Down Expand Up @@ -223,7 +219,7 @@ You can use the following tags to configure command line parsing rules:

### Tag `opt`

Specifies the name of the short or long flag whose data must be entered in the appropriate field. If no tag is specified, it will be automatically set to the value of the field name converted to kebab-case. For example: `UserName` converts to `user-name`.
Specifies the name of the short or long flag whose data must be entered in the appropriate field. If no tag is specified, it will be automatically set to the value of the field name converted to kebab-case. For example: `UserName` converts to `user-name`.

Has reserved values:

Expand Down
13 changes: 6 additions & 7 deletions args.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ type argMap map[string][]argValue
// the flag --no-verbose - is it the no-verbose flag or the objection
// for the verbose flag? This slice stores all available long flags
// declared in the data structure.
// func (am argMap) parse(args []string, shortFlags, longFlags flagMap) error {
func (am argMap) parse(args []string, flags map[string]int) error {
// Controls of parsing state of positional arguments.
var posState = struct {
posState := struct {
order int // real index of the positional argument
active bool // true if switch to parsing of positional arguments
}{}
Expand All @@ -58,7 +57,7 @@ func (am argMap) parse(args []string, flags map[string]int) error {
// to take the following argument in the course of current
// iteration and to skip next one iteration.
for i := 0; i < len(args); i++ {
var item = args[i]
item := args[i]

switch {
case item == "--":
Expand Down Expand Up @@ -212,7 +211,7 @@ func (am argMap) parse(args []string, flags map[string]int) error {

// The asFlat returns argMap as simple map[string][]string.
func (am argMap) asFlat() map[string][]string {
var result = make(map[string][]string, len(am))
result := make(map[string][]string, len(am))

for key, items := range am {
tmp := make([]string, 0, len(items))
Expand Down Expand Up @@ -281,9 +280,9 @@ func (am argMap) posValues() []string {
// Returns defValue with false as second param if the value
// is not found.
func (am argMap) flagValue(
shortFlag string,
longFlag string,
defValue string,
shortFlag,
longFlag,
defValue,
sepList string,
) ([]string, bool) {
var result []string
Expand Down
12 changes: 5 additions & 7 deletions decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func TestUnmarshalOptMix(t *testing.T) {
}

for i, test := range tests {
var d = data{}
d := data{}
if err := unmarshalOpt(&d, test); err != nil {
t.Error(err)
return // it makes no sense to display all errors
Expand Down Expand Up @@ -260,7 +260,7 @@ func TestUnmarshalOptNotStruct(t *testing.T) {
}
}()

var d = new(int)
d := new(int)
unmarshalOpt(d, []string{"/app", "5", "10"}) // panic is expected
}

Expand Down Expand Up @@ -335,9 +335,7 @@ func TestWrongList(t *testing.T) {

// TestStructUrl tests with pointer on struct.
func TestStructUrl(t *testing.T) {
var (
site url.URL
)
var site url.URL

split := func(str string) []string { return strings.Split(str, ":") }
test := split("./app:--site:%$")
Expand Down Expand Up @@ -476,7 +474,7 @@ func TestUnmarshalOptPositional(t *testing.T) {
ABC []int `opt:"[]" help:"position args as list"`
}

var d, sum = data{}, 0
d, sum := data{}, 0

if err := unmarshalOpt(&d, []string{"/app", "5", "10", "15"}); err != nil {
t.Error(err)
Expand Down Expand Up @@ -510,7 +508,7 @@ func TestUnmarshalOptPositional(t *testing.T) {

// TestStrToBool tests strToBool function.
func TestStrToBool(t *testing.T) {
var tests = []testBoolDataTestType{
tests := []testBoolDataTestType{
{"", false, true},
{"0", false, true},
{"1", true, true},
Expand Down
7 changes: 0 additions & 7 deletions doc.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,2 @@
// Package opt implements methods for manage arguments of the command-line.
package opt

const version = "1.0.3"

// Version returns the version of the module.
func Version() string {
return "v" + version
}
24 changes: 0 additions & 24 deletions doc_test.go

This file was deleted.

4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module github.com/goloop/opt

go 1.15
go 1.20

require (
github.com/goloop/scs v1.0.1
github.com/goloop/scs v1.1.1
)
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
github.com/goloop/scs v1.0.1 h1:6QnhDIH2pzrGrbwhCFSJWcqfjqu4z9cLfE3kpfeCx/4=
github.com/goloop/scs v1.0.1/go.mod h1:De464a22sqV3KyrR0mqa8qgS6nSFpdeX5ePKEJxXNxo=
github.com/robertkrimen/godocdown v0.0.0-20130622164427-0bfa04905481 h1:jMxcLa+VjJKhpCwbLUXAD15wJ+hhvXMLujCl3MkXpfM=
github.com/robertkrimen/godocdown v0.0.0-20130622164427-0bfa04905481/go.mod h1:C9WhFzY47SzYBIvzFqSvHIR6ROgDo4TtdTuRaOMjF/s=
github.com/goloop/scs v1.1.1 h1:ixqutFAtf1tZXZ/9nQLNKR0aRUIQiVGNozPnCfKssso=
github.com/goloop/scs v1.1.1/go.mod h1:pUuCj5l3EDy+r8m8VZ505Z60BFgtEQ7+Qh0/VmJvrr8=
2 changes: 1 addition & 1 deletion help.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func wrapHelpMsg(sep, str string, tab, wc int) []string {
// 0 - if such a container exists and its size is not limited (for slice),
// more than 0 if the number of elements in this container is limited (array).
func getOptionBlock(fcl fieldCastList, am argMap) (string, int) {
var lines = []string{}
lines := []string{}

// Go through all the fields, make a prefix for the help line,
// which includes the available arguments. Determine the largest
Expand Down
Loading

0 comments on commit 8181b56

Please sign in to comment.