Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
5767b41b
Commit
5767b41b
authored
Jan 14, 2015
by
Daniel Smith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make quantity flag work with pflag package
parent
30be0eea
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
0 deletions
+15
-0
quantity.go
pkg/api/resource/quantity.go
+7
-0
quantity_test.go
pkg/api/resource/quantity_test.go
+8
-0
No files found.
pkg/api/resource/quantity.go
View file @
5767b41b
...
@@ -386,6 +386,7 @@ type qFlag struct {
...
@@ -386,6 +386,7 @@ type qFlag struct {
dest
*
Quantity
dest
*
Quantity
}
}
// Sets the value of the internal Quantity. (used by flag & pflag)
func
(
qf
qFlag
)
Set
(
val
string
)
error
{
func
(
qf
qFlag
)
Set
(
val
string
)
error
{
q
,
err
:=
ParseQuantity
(
val
)
q
,
err
:=
ParseQuantity
(
val
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -396,10 +397,16 @@ func (qf qFlag) Set(val string) error {
...
@@ -396,10 +397,16 @@ func (qf qFlag) Set(val string) error {
return
nil
return
nil
}
}
// Converts the value of the internal Quantity to a string. (used by flag & pflag)
func
(
qf
qFlag
)
String
()
string
{
func
(
qf
qFlag
)
String
()
string
{
return
qf
.
dest
.
String
()
return
qf
.
dest
.
String
()
}
}
// States the type of flag this is (Quantity). (used by pflag)
func
(
qf
qFlag
)
Type
()
string
{
return
"quantity"
}
// QuantityFlag is a helper that makes a quantity flag (using standard flag package).
// QuantityFlag is a helper that makes a quantity flag (using standard flag package).
// Will panic if defaultValue is not a valid quantity.
// Will panic if defaultValue is not a valid quantity.
func
QuantityFlag
(
flagName
,
defaultValue
,
description
string
)
*
Quantity
{
func
QuantityFlag
(
flagName
,
defaultValue
,
description
string
)
*
Quantity
{
...
...
pkg/api/resource/quantity_test.go
View file @
5767b41b
...
@@ -22,6 +22,7 @@ import (
...
@@ -22,6 +22,7 @@ import (
"testing"
"testing"
fuzz
"github.com/google/gofuzz"
fuzz
"github.com/google/gofuzz"
"github.com/spf13/pflag"
"speter.net/go/exp/math/dec/inf"
"speter.net/go/exp/math/dec/inf"
)
)
...
@@ -487,3 +488,10 @@ func TestQFlagSet(t *testing.T) {
...
@@ -487,3 +488,10 @@ func TestQFlagSet(t *testing.T) {
t
.
Errorf
(
"Unexpected result %v != %v"
,
e
,
a
)
t
.
Errorf
(
"Unexpected result %v != %v"
,
e
,
a
)
}
}
}
}
func
TestQFlagIsPFlag
(
t
*
testing
.
T
)
{
var
pfv
pflag
.
Value
=
qFlag
{}
if
e
,
a
:=
"quantity"
,
pfv
.
Type
();
e
!=
a
{
t
.
Errorf
(
"Unexpected result %v != %v"
,
e
,
a
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment