1/*
2Copyright 2014 The Kubernetes Authors.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8    http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17package flag
18
19// StringFlag is a string flag compatible with flags and pflags that keeps track of whether it had a value supplied or not.
20type StringFlag struct {
21	// If Set has been invoked this value is true
22	provided bool
23	// The exact value provided on the flag
24	value string
25}
26
27func NewStringFlag(defaultVal string) StringFlag {
28	return StringFlag{value: defaultVal}
29}
30
31func (f *StringFlag) Default(value string) {
32	f.value = value
33}
34
35func (f StringFlag) String() string {
36	return f.value
37}
38
39func (f StringFlag) Value() string {
40	return f.value
41}
42
43func (f *StringFlag) Set(value string) error {
44	f.value = value
45	f.provided = true
46
47	return nil
48}
49
50func (f StringFlag) Provided() bool {
51	return f.provided
52}
53
54func (f *StringFlag) Type() string {
55	return "string"
56}
57