-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflag.gp_timestamp.go
211 lines (185 loc) · 6.58 KB
/
flag.gp_timestamp.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
///////////////////////////////////////////////////////////////////
//
// !!!!!!!!!!!! NEVER MODIFY THIS FILE MANUALLY !!!!!!!!!!!!
//
// This file was auto-generated by tool [github.com/gxlb/gogp]
// Last update at: [Sat Mar 20 2021 22:32 CST]
// Generate from:
// [github.com/gxlb/cli/internal/gp/flag.gp]
// [github.com/gxlb/cli/flag.gpg] [flag_timestamp]
//
// Tool [github.com/gxlb/gogp] info:
// CopyRight 2021 @Ally Dale. All rights reserved.
// Author : Ally Dale([email protected])
// Site : https://github.com/vipally
// Version : v4.0.0
//
///////////////////////////////////////////////////////////////////
// MIT License
//
// Copyright (c) 2021 Ally Dale <[email protected]>
//
// 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.
package cli
import (
"flag"
"fmt"
"cli/internal/impl"
"cli/internal/util"
)
// TimestampFlag define a value of type *impl.TimestampValue
type TimestampFlag struct {
//
//name related area
//
LogicName string // logic name of the flag
Name string // name of the flag
Aliases []string // aliases of the flag
Usage string // usage string
Required bool // if required
Hidden bool // hidden this flag
EnvVars []string // environment values
FilePath string // file path
//
//value related area
//
Target *impl.TimestampValue // Target value pointer outside
Default *impl.TimestampValue // Default value
DefaultText string // Default value display in help info
Layout string // Layout of the time format, default **2006-01-02T15:04:05 MST**
//
////////////////////////////////////////////////////////////////////////////
//area for parsing
target *impl.TimestampValue // target value pointer(maybe new(*impl.TimestampValue) if Target not set)
info impl.FlagInfo // parsed info of this flag
}
// init verify and init the flag info
func (f *TimestampFlag) init(namegen *util.NameGenenerator) error {
f.info.Flag = f
f.info.EnvVars = append([]string{}, f.EnvVars...)
f.info.Usage = f.Usage
f.info.DefaultText = f.DefaultText
f.info.Required = f.Required
f.info.Hidden = f.Hidden
f.info.FilePath = f.FilePath
f.info.HasBeenSet = false
f.info.Name = namegen.GetOrGenName(f.Name)
f.info.NonameFlag = f.info.Name != f.Name
f.info.LogicName = impl.FlagLogicName(f.Name, f.LogicName)
f.info.ValueName = impl.FlagValueName(f.LogicName)
impl.MergeNames(f.info.Name, f.Aliases, &f.info.Names) //use v.info.Name to enable auto-generated name
//make the target pointer
if f.Target != nil {
f.target = f.Target
} else {
f.target = impl.NewEmptyTimestampValue(f.Layout)
}
if f.Name == "" && f.LogicName == "" { // Name & LogicName cannot both missing
return fmt.Errorf("flag missing both Name & LogicName: %v", f)
}
if f.Name == "" && len(f.Aliases) > 0 { // Noname ones must without Aliases
return fmt.Errorf("flag %s missing name, but has Aliases %v", f.info.LogicName, f.Aliases)
}
if err := f.validateValues(f.Default); err != nil { // verify default values
return fmt.Errorf("default value invalid: %s", err.Error())
}
if err := util.FiltNames(f.info.Names); err != nil { // verify name duplicate
return fmt.Errorf("flag %s.Names error: %s", f.info.LogicName, err.Error())
}
if err := util.FiltNames(f.info.EnvVars); err != nil { // verify EnvVars duplicate
return fmt.Errorf("flag %s.EnvVars error: %s", f.info.LogicName, err.Error())
}
return nil
}
// IsSet check if value was set
func (f *TimestampFlag) IsSet() bool {
return f.info.HasBeenSet
}
//GetLogicName returns the logic name of the falg
func (f *TimestampFlag) GetLogicName() string {
return f.info.LogicName
}
//GetValueName returns the value name of the falg
func (f *TimestampFlag) GetValueName() string {
return f.info.ValueName
}
// Names returns the names of the flag
func (f *TimestampFlag) Names() []string {
return f.info.Names
}
// IsRequired returns whether or not the flag is required
func (f *TimestampFlag) IsRequired() bool {
return f.Required
}
// TakesValue returns true of the flag takes a value, otherwise false
func (f *TimestampFlag) TakesValue() bool {
return false
}
// GetUsage returns the usage string for the flag
func (f *TimestampFlag) GetUsage() string {
return f.info.Usage
}
// GetValue returns the flags value as string representation.
func (f *TimestampFlag) GetValue() string {
return ""
}
// Apply coordinate the value to flagset
func (f *TimestampFlag) Apply(set *flag.FlagSet) error {
return nil
}
// String return the value for view
func (f *TimestampFlag) String() string {
return ""
}
// ValidateValues verify if all values are valid
func (f *TimestampFlag) ValidateValues() error {
return f.validateValues(f.target)
}
// Info returns parsed info of this flag, the returned object must READ-ONLY
func (v *TimestampFlag) Info() *impl.FlagInfo {
return &v.info
}
// Reset clean the last parsed value of this flag
func (f *TimestampFlag) Reset() {
f.target.Reset()
f.info.HasBeenSet = false
}
// for default value verify
func (f *TimestampFlag) validateValues(values *impl.TimestampValue) error {
return f.validValue(values)
}
// check if value if valid for this flag
func (f *TimestampFlag) validValue(value *impl.TimestampValue) error {
return nil
}
// Timestamp looks up the value of a local TimestampFlag
func (c *Context) Timestamp(name string) *impl.TimestampValue {
if fs := lookupFlagSet(name, c); fs != nil {
return lookupTimestamp(name, fs)
}
return nil
}
func lookupTimestamp(name string, set *flag.FlagSet) *impl.TimestampValue {
f := set.Lookup(name)
if f != nil {
//TODO:
}
return nil
}
var _ impl.Flag = (*TimestampFlag)(nil) //for interface verification only