github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/bench/tools/aisloader/flag.go (about) 1 // Package aisloader 2 /* 3 * Copyright (c) 2018-2022, NVIDIA CORPORATION. All rights reserved. 4 */ 5 package aisloader 6 7 import ( 8 "flag" 9 "strconv" 10 "time" 11 12 "github.com/NVIDIA/aistore/cmn/cos" 13 ) 14 15 type ( 16 BoolExt struct { 17 IsSet bool 18 Val bool 19 } 20 21 DurationExt struct { 22 IsSet bool 23 Val time.Duration 24 } 25 ) 26 27 // interface guard 28 var ( 29 _ flag.Value = (*BoolExt)(nil) 30 _ flag.Value = (*DurationExt)(nil) 31 ) 32 33 func (b *BoolExt) Set(s string) (err error) { 34 b.Val, err = cos.ParseBool(s) 35 b.IsSet = true 36 return err 37 } 38 39 func (b *BoolExt) Get() any { return b.Val } 40 func (b *BoolExt) String() string { return strconv.FormatBool(b.Val) } 41 func (*BoolExt) IsBoolFlag() bool { return true } 42 43 func BoolExtVar(f *flag.FlagSet, p *BoolExt, name, usage string) { 44 f.Var(p, name, usage) 45 } 46 47 func (d *DurationExt) Set(s string) (err error) { 48 d.Val, err = time.ParseDuration(s) 49 d.IsSet = true 50 return err 51 } 52 53 func (d *DurationExt) Get() any { return d.Val } 54 func (d *DurationExt) String() string { return d.Val.String() } 55 func (*DurationExt) IsBoolFlag() bool { return false } 56 57 func DurationExtVar(f *flag.FlagSet, p *DurationExt, name string, defValue time.Duration, usage string) { 58 p.Val = defValue 59 f.Var(p, name, usage) 60 }