Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
xflags
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Jira
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Monitor
Service Desk
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OSS
Libraries
Go
Application
xflags
Compare revisions
v1.3.1 to v1.4.0
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
oss/libraries/go/application/xflags
Select target project
No results found
v1.4.0
Select Git revision
Branches
master
Tags
v1.0.0
v1.1.0
v1.1.1
v1.10.0
v1.10.1
v1.10.2
v1.11.0
v1.12.0
v1.13.0
v1.13.1
v1.13.2
v1.14.0
v1.15.0
v1.16.0
v1.16.1
v1.16.2
v1.16.3
v1.16.4
v1.16.5
v1.2.0
v1.2.1
v1.2.2
v1.2.3
v1.3.0
v1.3.1
v1.4.0
v1.5.0
v1.6.0
v1.7.0
v1.8.0
v1.8.1
v1.8.2
v1.8.3
v1.9.0
35 results
Swap
Target
oss/libraries/go/application/xflags
Select target project
oss/libraries/go/application/xflags
1 result
v1.3.1
Select Git revision
Branches
master
Tags
v1.0.0
v1.1.0
v1.1.1
v1.10.0
v1.10.1
v1.10.2
v1.11.0
v1.12.0
v1.13.0
v1.13.1
v1.13.2
v1.14.0
v1.15.0
v1.16.0
v1.16.1
v1.16.2
v1.16.3
v1.16.4
v1.16.5
v1.2.0
v1.2.1
v1.2.2
v1.2.3
v1.3.0
v1.3.1
v1.4.0
v1.5.0
v1.6.0
v1.7.0
v1.8.0
v1.8.1
v1.8.2
v1.8.3
v1.9.0
35 results
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source (4)
feat new function GetDefaults()
· 65f72a7c
Volker Schukai
authored
2 years ago
65f72a7c
feat new Execute() Method for the automatic execution of command
· 4d3fd0f0
Volker Schukai
authored
2 years ago
4d3fd0f0
Bump version to 1.4.0
· 7bdb668e
Volker Schukai
authored
2 years ago
7bdb668e
Update changelog
· a520513e
Volker Schukai
authored
2 years ago
a520513e
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
CHANGELOG.md
+8
-0
8 additions, 0 deletions
CHANGELOG.md
api.go
+52
-0
52 additions, 0 deletions
api.go
api_test.go
+30
-21
30 additions, 21 deletions
api_test.go
parse.go
+15
-1
15 additions, 1 deletion
parse.go
release.json
+1
-1
1 addition, 1 deletion
release.json
with
106 additions
and
23 deletions
CHANGELOG.md
View file @
a520513e
<a
name=
"v1.4.0"
></a>
## [v1.4.0] - 2022-10-09
### Add Features
-
feat new Execute() Method for the automatic execution of command
-
feat new function GetDefaults()
<a
name=
"v1.3.1"
></a>
<a
name=
"v1.3.1"
></a>
## [v1.3.1] - 2022-10-08
## [v1.3.1] - 2022-10-08
### Bug Fixes
### Bug Fixes
...
@@ -52,6 +59,7 @@
...
@@ -52,6 +59,7 @@
<a
name=
"v1.0.0"
></a>
<a
name=
"v1.0.0"
></a>
## v1.0.0 - 2022-10-04
## v1.0.0 - 2022-10-04
[
v1.4.0
]:
https://gitlab.schukai.com/oss/libraries/go/application/xflags/compare/v1.3.1...v1.4.0
[
v1.3.1
]:
https://gitlab.schukai.com/oss/libraries/go/application/xflags/compare/v1.3.0...v1.3.1
[
v1.3.1
]:
https://gitlab.schukai.com/oss/libraries/go/application/xflags/compare/v1.3.0...v1.3.1
[
v1.3.0
]:
https://gitlab.schukai.com/oss/libraries/go/application/xflags/compare/v1.2.3...v1.3.0
[
v1.3.0
]:
https://gitlab.schukai.com/oss/libraries/go/application/xflags/compare/v1.2.3...v1.3.0
[
v1.2.3
]:
https://gitlab.schukai.com/oss/libraries/go/application/xflags/compare/v1.2.2...v1.2.3
[
v1.2.3
]:
https://gitlab.schukai.com/oss/libraries/go/application/xflags/compare/v1.2.2...v1.2.3
...
...
This diff is collapsed.
Click to expand it.
api.go
View file @
a520513e
...
@@ -6,10 +6,52 @@ package xflags
...
@@ -6,10 +6,52 @@ package xflags
import
(
import
(
"bytes"
"bytes"
"flag"
"flag"
"fmt"
"io"
"io"
"os"
"reflect"
"reflect"
)
)
// Execute executes the command line arguments and calls the functions.
func
Execute
[
C
any
,
D
any
](
cmd
C
,
cnf
D
)
*
Settings
[
C
]
{
return
execute
(
cmd
,
cnf
,
os
.
Args
[
0
],
os
.
Args
[
1
:
])
}
func
(
s
*
Settings
[
C
])
PrintFlagOutput
()
{
fmt
.
Println
(
s
.
command
.
flagSet
.
Output
())
}
// execute is the internal implementation of Execute.
func
execute
[
C
any
,
D
any
](
cmd
C
,
cnf
D
,
name
string
,
args
[]
string
)
*
Settings
[
C
]
{
instance
:=
New
(
name
,
cmd
)
if
instance
.
HasErrors
()
{
return
instance
}
instance
.
SetShadow
(
cnf
)
if
instance
.
HasErrors
()
{
return
instance
}
instance
.
Parse
(
args
)
if
instance
.
HelpRequested
()
{
for
i
,
err
:=
range
instance
.
errors
{
if
err
==
flag
.
ErrHelp
{
instance
.
errors
=
append
(
instance
.
errors
[
:
i
],
instance
.
errors
[
i
+
1
:
]
...
)
}
}
instance
.
PrintFlagOutput
()
return
instance
}
if
instance
.
HasErrors
()
{
return
instance
}
instance
.
Execute
()
return
instance
}
// New creates a new instance of the settings.
// New creates a new instance of the settings.
// name should be the name of the command and comes from the first argument of the command line.
// name should be the name of the command and comes from the first argument of the command line.
// os.Args[0] is a good choice.
// os.Args[0] is a good choice.
...
@@ -43,3 +85,13 @@ func (s *Settings[C]) Output() string {
...
@@ -43,3 +85,13 @@ func (s *Settings[C]) Output() string {
func
(
s
*
Settings
[
C
])
Args
()
[]
string
{
func
(
s
*
Settings
[
C
])
Args
()
[]
string
{
return
s
.
args
return
s
.
args
}
}
// GetDefaults returns the default values of the settings.
func
(
s
*
Settings
[
C
])
GetDefaults
()
string
{
mem
:=
s
.
flagOutput
s
.
flagOutput
.
(
*
bytes
.
Buffer
)
.
Reset
()
s
.
command
.
flagSet
.
PrintDefaults
()
r
:=
s
.
flagOutput
.
(
*
bytes
.
Buffer
)
.
String
()
s
.
flagOutput
=
mem
return
r
}
This diff is collapsed.
Click to expand it.
api_test.go
View file @
a520513e
...
@@ -8,22 +8,31 @@ import (
...
@@ -8,22 +8,31 @@ import (
"testing"
"testing"
)
)
//func TestUsage(t *testing.T) {
func
TestUsage
(
t
*
testing
.
T
)
{
//
// commands := New("root", CmdTest1{})
commands
:=
New
(
"root"
,
CmdTest1
{})
// args := []string{"-h"}
args
:=
[]
string
{
"-h"
}
//
// commands.Parse(args)
commands
.
Parse
(
args
)
//
// assert.False(t, commands.HasErrors())
assert
.
True
(
t
,
commands
.
HelpRequested
())
// if commands.HasErrors() {
// t.Log(commands.Errors())
usage
:=
commands
.
GetDefaults
()
// }
assert
.
Equal
(
t
,
" -a
\t
Message A
\n
-x int
\n
\t
Message X
\n
"
,
usage
)
//
// usage := commands.Usage()
}
// assert.NotEmpty(t, usage)
func
TestExecute
(
t
*
testing
.
T
)
{
//
instance
:=
execute
(
"root"
,
CmdTest1
{},
"test"
,
[]
string
{
"-a"
,
"hello"
,
"-x"
,
"1"
})
//}
assert
.
NotNil
(
t
,
instance
)
}
func
TestExecuteHelp
(
t
*
testing
.
T
)
{
cnf
:=
struct
{
}{}
instance
:=
execute
(
CmdTest1
{},
&
cnf
,
"test"
,
[]
string
{
"-h"
})
assert
.
False
(
t
,
instance
.
HasErrors
())
}
func
TestNewIntWithError
(
t
*
testing
.
T
)
{
func
TestNewIntWithError
(
t
*
testing
.
T
)
{
...
@@ -47,17 +56,17 @@ func TestNew(t *testing.T) {
...
@@ -47,17 +56,17 @@ func TestNew(t *testing.T) {
}
}
type
CmdTest1
struct
{
type
CmdTest1
struct
{
A
bool
`short:"a"`
A
bool
`short:"a"
description:"Message A"
`
Sub1
struct
{
Sub1
struct
{
B
bool
`short:"b"`
B
bool
`short:"b"
description:"Message B"
`
Sub2
struct
{
Sub2
struct
{
C
bool
`short:"c"`
C
bool
`short:"c"
description:"Message C"
`
Sub3
struct
{
Sub3
struct
{
D
bool
`short:"d"`
D
bool
`short:"d"
description:"Message D"
`
}
`command:"sub3"`
}
`command:"sub3"`
}
`command:"sub2"`
}
`command:"sub2"`
}
`command:"sub1"`
}
`command:"sub1"`
aa
int
`short:"x"`
aa
int
`short:"x"
description:"Message X"
`
}
}
func
TestCommand2
(
t
*
testing
.
T
)
{
func
TestCommand2
(
t
*
testing
.
T
)
{
...
...
This diff is collapsed.
Click to expand it.
parse.go
View file @
a520513e
...
@@ -3,7 +3,10 @@
...
@@ -3,7 +3,10 @@
package
xflags
package
xflags
import
"os"
import
(
"flag"
"os"
)
// ParseOsArgs parses the os.Args.
// ParseOsArgs parses the os.Args.
func
(
s
*
Settings
[
C
])
ParseOsArgs
()
*
Settings
[
C
]
{
func
(
s
*
Settings
[
C
])
ParseOsArgs
()
*
Settings
[
C
]
{
...
@@ -38,3 +41,14 @@ func (s *Settings[C]) Parse(args []string) *Settings[C] {
...
@@ -38,3 +41,14 @@ func (s *Settings[C]) Parse(args []string) *Settings[C] {
return
s
return
s
}
}
func
(
s
*
Settings
[
C
])
HelpRequested
()
bool
{
for
_
,
err
:=
range
s
.
errors
{
if
err
==
flag
.
ErrHelp
{
return
true
}
}
return
false
}
This diff is collapsed.
Click to expand it.
release.json
View file @
a520513e
{
"version"
:
"1.
3.1
"
}
{
"version"
:
"1.
4.0
"
}
This diff is collapsed.
Click to expand it.