@@ -26,8 +26,9 @@ func TestArgableTypes(t *testing.T) {
2626 err = intArg .Set ("42" )
2727 test .Ok (t , err )
2828 test .Equal (t , i , 42 )
29- test .Equal (t , intArg .Type (), "int" )
29+ test .Equal (t , intArg .Type (), format . TypeInt )
3030 test .Equal (t , intArg .String (), "42" )
31+ test .Equal (t , intArg .Usage (), "Set an int value" )
3132 test .Equal (t , intArg .Default (), "" )
3233 })
3334
@@ -51,7 +52,8 @@ func TestArgableTypes(t *testing.T) {
5152 err = intArg .Set ("42" )
5253 test .Ok (t , err )
5354 test .Equal (t , i , int8 (42 ))
54- test .Equal (t , intArg .Type (), "int8" )
55+ test .Equal (t , intArg .Type (), format .TypeInt8 )
56+ test .Equal (t , intArg .Usage (), "Set an int8 value" )
5557 test .Equal (t , intArg .String (), "42" )
5658 })
5759
@@ -75,7 +77,8 @@ func TestArgableTypes(t *testing.T) {
7577 err = intArg .Set ("42" )
7678 test .Ok (t , err )
7779 test .Equal (t , i , int16 (42 ))
78- test .Equal (t , intArg .Type (), "int16" )
80+ test .Equal (t , intArg .Type (), format .TypeInt16 )
81+ test .Equal (t , intArg .Usage (), "Set an int16 value" )
7982 test .Equal (t , intArg .String (), "42" )
8083 })
8184
@@ -99,7 +102,8 @@ func TestArgableTypes(t *testing.T) {
99102 err = intArg .Set ("42" )
100103 test .Ok (t , err )
101104 test .Equal (t , i , int32 (42 ))
102- test .Equal (t , intArg .Type (), "int32" )
105+ test .Equal (t , intArg .Type (), format .TypeInt32 )
106+ test .Equal (t , intArg .Usage (), "Set an int32 value" )
103107 test .Equal (t , intArg .String (), "42" )
104108 })
105109
@@ -123,7 +127,8 @@ func TestArgableTypes(t *testing.T) {
123127 err = intArg .Set ("42" )
124128 test .Ok (t , err )
125129 test .Equal (t , i , int64 (42 ))
126- test .Equal (t , intArg .Type (), "int64" )
130+ test .Equal (t , intArg .Type (), format .TypeInt64 )
131+ test .Equal (t , intArg .Usage (), "Set an int64 value" )
127132 test .Equal (t , intArg .String (), "42" )
128133 })
129134
@@ -147,7 +152,8 @@ func TestArgableTypes(t *testing.T) {
147152 err = intArg .Set ("42" )
148153 test .Ok (t , err )
149154 test .Equal (t , i , 42 )
150- test .Equal (t , intArg .Type (), "uint" )
155+ test .Equal (t , intArg .Type (), format .TypeUint )
156+ test .Equal (t , intArg .Usage (), "Set a uint value" )
151157 test .Equal (t , intArg .String (), "42" )
152158 })
153159
@@ -172,6 +178,7 @@ func TestArgableTypes(t *testing.T) {
172178 test .Ok (t , err )
173179 test .Equal (t , i , uint8 (42 ))
174180 test .Equal (t , intArg .Type (), "uint8" )
181+ test .Equal (t , intArg .Usage (), "Set a uint8 value" )
175182 test .Equal (t , intArg .String (), "42" )
176183 })
177184
@@ -195,7 +202,8 @@ func TestArgableTypes(t *testing.T) {
195202 err = intArg .Set ("42" )
196203 test .Ok (t , err )
197204 test .Equal (t , i , uint16 (42 ))
198- test .Equal (t , intArg .Type (), "uint16" )
205+ test .Equal (t , intArg .Type (), format .TypeUint16 )
206+ test .Equal (t , intArg .Usage (), "Set a uint16 value" )
199207 test .Equal (t , intArg .String (), "42" )
200208 })
201209
@@ -219,7 +227,8 @@ func TestArgableTypes(t *testing.T) {
219227 err = intArg .Set ("42" )
220228 test .Ok (t , err )
221229 test .Equal (t , i , uint32 (42 ))
222- test .Equal (t , intArg .Type (), "uint32" )
230+ test .Equal (t , intArg .Type (), format .TypeUint32 )
231+ test .Equal (t , intArg .Usage (), "Set a uint32 value" )
223232 test .Equal (t , intArg .String (), "42" )
224233 })
225234
@@ -243,7 +252,8 @@ func TestArgableTypes(t *testing.T) {
243252 err = intArg .Set ("42" )
244253 test .Ok (t , err )
245254 test .Equal (t , i , uint64 (42 ))
246- test .Equal (t , intArg .Type (), "uint64" )
255+ test .Equal (t , intArg .Type (), format .TypeUint64 )
256+ test .Equal (t , intArg .Usage (), "Set a uint64 value" )
247257 test .Equal (t , intArg .String (), "42" )
248258 })
249259
@@ -267,7 +277,8 @@ func TestArgableTypes(t *testing.T) {
267277 err = intArg .Set ("42" )
268278 test .Ok (t , err )
269279 test .Equal (t , i , uintptr (42 ))
270- test .Equal (t , intArg .Type (), "uintptr" )
280+ test .Equal (t , intArg .Type (), format .TypeUintptr )
281+ test .Equal (t , intArg .Usage (), "Set a uintptr value" )
271282 test .Equal (t , intArg .String (), "42" )
272283 })
273284
@@ -291,7 +302,8 @@ func TestArgableTypes(t *testing.T) {
291302 err = floatArg .Set ("3.14159" )
292303 test .Ok (t , err )
293304 test .Equal (t , f , 3.14159 )
294- test .Equal (t , floatArg .Type (), "float32" )
305+ test .Equal (t , floatArg .Type (), format .TypeFloat32 )
306+ test .Equal (t , floatArg .Usage (), "Set a float32 value" )
295307 test .Equal (t , floatArg .String (), "3.14159" )
296308 })
297309
@@ -315,7 +327,8 @@ func TestArgableTypes(t *testing.T) {
315327 err = floatArg .Set ("3.14159" )
316328 test .Ok (t , err )
317329 test .Equal (t , f , 3.14159 )
318- test .Equal (t , floatArg .Type (), "float64" )
330+ test .Equal (t , floatArg .Type (), format .TypeFloat64 )
331+ test .Equal (t , floatArg .Usage (), "Set a float64 value" )
319332 test .Equal (t , floatArg .String (), "3.14159" )
320333 })
321334
@@ -339,7 +352,8 @@ func TestArgableTypes(t *testing.T) {
339352 err = boolArg .Set (format .True )
340353 test .Ok (t , err )
341354 test .Equal (t , b , true )
342- test .Equal (t , boolArg .Type (), "bool" )
355+ test .Equal (t , boolArg .Type (), format .TypeBool )
356+ test .Equal (t , boolArg .Usage (), "Set a bool value" )
343357 test .Equal (t , boolArg .String (), format .True )
344358 })
345359
@@ -365,7 +379,8 @@ func TestArgableTypes(t *testing.T) {
365379 err = strArg .Set ("newvalue" )
366380 test .Ok (t , err )
367381 test .Equal (t , str , "newvalue" )
368- test .Equal (t , strArg .Type (), "string" )
382+ test .Equal (t , strArg .Type (), format .TypeString )
383+ test .Equal (t , strArg .Usage (), "Set a string value" )
369384 test .Equal (t , strArg .String (), "newvalue" )
370385 })
371386
@@ -378,7 +393,8 @@ func TestArgableTypes(t *testing.T) {
378393 err = byteArg .Set ("5e" )
379394 test .Ok (t , err )
380395 test .EqualFunc (t , byt , []byte ("^" ), bytes .Equal )
381- test .Equal (t , byteArg .Type (), "bytesHex" )
396+ test .Equal (t , byteArg .Type (), format .TypeBytesHex )
397+ test .Equal (t , byteArg .Usage (), "Set a byte slice value" )
382398 test .Equal (t , byteArg .String (), "5e" )
383399 })
384400
@@ -405,7 +421,8 @@ func TestArgableTypes(t *testing.T) {
405421 want , err := time .Parse (time .RFC3339 , "2024-07-17T07:38:05Z" )
406422 test .Ok (t , err )
407423 test .Equal (t , tyme , want )
408- test .Equal (t , timeArg .Type (), "time" )
424+ test .Equal (t , timeArg .Type (), format .TypeTime )
425+ test .Equal (t , timeArg .Usage (), "Set a time value" )
409426 test .Equal (t , timeArg .String (), "2024-07-17T07:38:05Z" )
410427 })
411428
@@ -432,7 +449,8 @@ func TestArgableTypes(t *testing.T) {
432449 want , err := time .ParseDuration ("300ms" )
433450 test .Ok (t , err )
434451 test .Equal (t , duration , want )
435- test .Equal (t , durationArg .Type (), "duration" )
452+ test .Equal (t , durationArg .Type (), format .TypeDuration )
453+ test .Equal (t , durationArg .Usage (), "Set a duration value" )
436454 test .Equal (t , durationArg .String (), "300ms" )
437455 })
438456
@@ -456,7 +474,8 @@ func TestArgableTypes(t *testing.T) {
456474 err = ipArg .Set ("192.0.2.1" )
457475 test .Ok (t , err )
458476 test .DiffBytes (t , ip , net .ParseIP ("192.0.2.1" ))
459- test .Equal (t , ipArg .Type (), "ip" )
477+ test .Equal (t , ipArg .Type (), format .TypeIP )
478+ test .Equal (t , ipArg .Usage (), "Set an IP address" )
460479 test .Equal (t , ipArg .String (), "192.0.2.1" )
461480 })
462481
@@ -471,3 +490,19 @@ func TestArgableTypes(t *testing.T) {
471490 test .True (t , errors .Is (err , parse .Err ))
472491 })
473492}
493+
494+ func TestDefaults (t * testing.T ) {
495+ str , err := arg .New (new (string ), "str" , "A string" , arg.Config [string ]{DefaultValue : pointer ("hello" )})
496+ test .Ok (t , err )
497+
498+ intArg , err := arg .New (new (int ), "int" , "A string" , arg.Config [int ]{DefaultValue : pointer (27 )})
499+ test .Ok (t , err )
500+
501+ test .Equal (t , str .Default (), "hello" )
502+ test .Equal (t , intArg .Default (), "27" )
503+ }
504+
505+ // pointer creates a new variable of the given value and returns its pointer.
506+ func pointer [T any ](value T ) * T {
507+ return & value
508+ }
0 commit comments